<?php

return [

    /*
    |--------------------------------------------------------------------------
    | Octoparse Open API Configuration
    |--------------------------------------------------------------------------
    |
    | Configuration for the Octoparse Cloud scraping integration. Daily Cloud
    | tasks run on the Octoparse side; this backend pulls the resulting data
    | through their Open API and upserts it into octoparse_records.
    |
    */

    /**
     * Enable or disable Octoparse synchronization
     */
    'sync_enabled' => env('OCTOPARSE_SYNC_ENABLED', false),

    /**
     * API connection
     */
    'api' => [
        'base_url' => env('OCTOPARSE_API_URL', 'https://openapi.octoparse.com'),
        'username' => env('OCTOPARSE_API_USERNAME', ''),
        'password' => env('OCTOPARSE_API_PASSWORD', ''),
        // Cache TTL ceiling. Real TTL comes from "expires_in" returned by the
        // API; this is only an upper bound used when caching the access token.
        'access_token_ttl' => (int) env('OCTOPARSE_ACCESS_TOKEN_TTL', 3600 * 7),
        // Refresh tokens live longer; cache for up to 30 days by default.
        'refresh_token_ttl' => (int) env('OCTOPARSE_REFRESH_TOKEN_TTL', 86400 * 30),
        'request_timeout' => (int) env('OCTOPARSE_REQUEST_TIMEOUT', 60),
    ],

    /**
     * Registered Octoparse tasks. Edit this list to enable importing data
     * from each task. Keys are the Octoparse task UUIDs.
     *
     * Each entry supports:
     *   - label              : human-readable label for the backoffice UI
     *   - unique_key_field   : field name (from the scraped payload) used as
     *                          the upsert key. If null, every row is appended
     *                          and a hash of the whole payload is used.
     *   - enabled            : whether the scheduled import processes it
     */
    'tasks' => [
        'ec986a65-42e2-4cfc-42d7-f020c275886a' => [
            'label' => 'OKTE, a.s.',
            'unique_key_field' => 'Field1',
            'enabled' => true,
        ],
        'b075cd25-310d-ca47-f316-cf57f0a779ba' => [
            'label' => 'EPEX SPOT SE',
            'unique_key_field' => 'Field1',
            'enabled' => true,
        ],
        '79f09e5c-4865-ee0a-5957-963cb027402d' => [
            'label' => 'HUPX Ltd. - Go Markets',
            'unique_key_field' => 'Field1',
            'enabled' => true,
        ],
        '5fa84be7-5fb3-c842-1f0e-72130e239994' => [
            'label' => 'HUPX Ltd. - Spot Markets',
            'unique_key_field' => 'Field1',
            'enabled' => true,
        ],
        'e491fc3c-a047-c092-10ff-7984f182bc83' => [
            'label' => 'Gestore dei mercati energetici spa (GME)',
            'unique_key_field' => 'Field1',
            'enabled' => true,
        ],
        '280f7e04-092c-ba67-b2ae-3ca21b1e8de7' => [
            'label' => 'HENEX SA',
            'unique_key_field' => 'Field1',
            'enabled' => true,
        ],
        'ac84d148-3351-cbe8-079f-c06a2d0044a9' => [
            'label' => 'EXAA Abwicklungsstelle für Energieprodukte AG',
            'unique_key_field' => 'Field1',
            'enabled' => true,
        ],
        'eec2d7a9-53ce-203a-46ee-3f57eeb5f038' => [
            'label' => 'OTE, a.s.',
            'unique_key_field' => 'Field1',
            'enabled' => true,
        ],
        'b80a6651-84a4-a8c9-a734-e9ffc7e2b477' => [
            'label' => 'Towarowa Giełda Energii S.A.',
            'unique_key_field' => 'Field1',
            'enabled' => true,
        ],
        '6059caa8-37b3-7d94-c70b-4deb1cdbad1e' => [
            'label' => 'BSP d.o.o.',
            'unique_key_field' => 'Field1',
            'enabled' => true,
        ],
        '6b86c435-c624-501b-541f-589961ce0d58' => [
            'label' => 'Central European Gas Hub, CEGH, Wiener Börse AG',
            'unique_key_field' => 'Field1',
            'enabled' => true,
        ],
        '30495d41-48d9-51ea-f102-3dec6419b9aa' => [
            'label' => 'ICE Endex',
            'unique_key_field' => 'Field1',
            'enabled' => true,
        ],
        '48b36608-4f6c-fe53-3d33-c418cab24226' => [
            'label' => 'Independent Bulgarian Energy Exchange',
            'unique_key_field' => 'Participants',
            'enabled' => true,
        ],
        '7d1b6163-1af1-3a60-f063-ebae21e2256c' => [
            'label' => 'N2EX/Nord Pool Spot AS',
            'unique_key_field' => 'Field1',
            'enabled' => true,
        ],
        '5f45aefa-8a50-f25c-71b4-9d2f06aabd75' => [
            'label' => 'ICE Futures Europe',
            'unique_key_field' => 'Field1',
            'enabled' => true,
        ],
        '78608211-9fd6-ced7-b4a3-90b8931a2018' => [
            'label' => 'Balkan Gas Hub EAD',
            'unique_key_field' => 'Member',
            'enabled' => true,
        ],
        '4b1d2806-b7e5-b7a8-dda2-71a3db829cb9' => [
            'label' => 'European Energy Exchange AG Regulated Market',
            'unique_key_field' => 'Field1',
            'enabled' => true,
        ],
        '6c654208-22bc-2c54-61ea-bdc583bee811' => [
            'label' => 'MEFF Sociedad Rectora del Mercado de Productos Derivados, S.A.',
            'unique_key_field' => 'Field1_text',
            'enabled' => true,
        ],
        'e868a0cf-f881-3e42-4bbd-fb297c93ee7a' => [
            'label' => 'Bulgarian Energy Trading Platform AD',
            'unique_key_field' => 'Name',
            'enabled' => true,
        ],
        '10fcc698-e6d0-1d89-fe39-bdc4ae53f656' => [
            'label' => 'OMIP - Pólo Português, S.G.M.R., S.A.',
            'unique_key_field' => 'Entity',
            'enabled' => true,
        ],
        '494acb64-458b-9fc4-fb51-a10572a7189b' => [
            'label' => 'Euronext Amsterdam N.V.',
            'unique_key_field' => 'NAME_ASCENDING',
            'enabled' => true,
        ],
    ],

    /**
     * Import settings
     */
    'import' => [
        'page_size' => (int) env('OCTOPARSE_PAGE_SIZE', 1000),
        // When true, the importer uses /api/notexportdata/* endpoints (only
        // new rows since last export) instead of /api/alldata/*. Combine with
        // markDataExported to avoid pulling the same rows twice.
        'use_not_exported_endpoint' => (bool) env('OCTOPARSE_USE_NOT_EXPORTED', false),
        // Octoparse hard limit: 20 req/sec. Keep a margin to avoid 429s.
        'rate_limit_delay_ms' => (int) env('OCTOPARSE_RATE_LIMIT_DELAY_MS', 60),
        'rate_limit_max_per_sec' => (int) env('OCTOPARSE_RATE_LIMIT_MAX_PER_SEC', 16),
        'max_retries' => (int) env('OCTOPARSE_MAX_RETRIES', 5),
        'backoff_base_ms' => (int) env('OCTOPARSE_BACKOFF_BASE_MS', 1000),
    ],

    /**
     * Email report configuration
     */
    'email_report' => [
        'recipients' => env('OCTOPARSE_REPORT_RECIPIENTS', 'christian.freitas@eae.pt'),
        'only_on_error' => (bool) env('OCTOPARSE_REPORT_ONLY_ON_ERROR', false),
    ],

    /**
     * Daily import schedule (24h, server timezone)
     */
    'schedule' => [
        'time' => env('OCTOPARSE_SYNC_TIME', '05:00'),
    ],

];
