<?php

return [
    'name'           => 'WhatsApp',
    'module_version' => '1.0.0',

    /*
    |--------------------------------------------------------------------------
    | Queue
    |--------------------------------------------------------------------------
    | Outbound messages are ALWAYS persisted to wa_messages first, then handed
    | to a queued job. The global QUEUE_CONNECTION is 'sync' in this app, so we
    | pin WhatsApp work to its own connection/queue explicitly. Run the worker:
    |   php artisan queue:work whatsapp_db --queue=whatsapp --tries=0
    */
    'queue' => [
        'connection' => env('WHATSAPP_QUEUE_CONNECTION', 'whatsapp_db'),
        'queue'      => env('WHATSAPP_QUEUE', 'whatsapp'),
    ],

    /*
    |--------------------------------------------------------------------------
    | Anti-ban throttle
    |--------------------------------------------------------------------------
    | Minimum / maximum random delay (seconds) inserted between two consecutive
    | sends on the SAME channel. Randomised to avoid a robotic cadence that gets
    | unofficial (QR) numbers flagged. Meta Cloud numbers can use a smaller gap.
    */
    'throttle' => [
        'meta' => ['min' => (int) env('WHATSAPP_THROTTLE_META_MIN', 1), 'max' => (int) env('WHATSAPP_THROTTLE_META_MAX', 3)],
        'web'  => ['min' => (int) env('WHATSAPP_THROTTLE_WEB_MIN', 4),  'max' => (int) env('WHATSAPP_THROTTLE_WEB_MAX', 12)],
    ],

    /*
    |--------------------------------------------------------------------------
    | Sending behaviour (anti-ban realism) — defaults
    |--------------------------------------------------------------------------
    | Per-business overrides live in wa_settings (gap_min/gap_max/typing_*).
    |  - gap_min/gap_max : randomised seconds BETWEEN two messages on a channel.
    |  - typing_per_char_ms : "typing…" time added per character of the message.
    |  - typing_min_ms/typing_max_ms : clamp for the typing indicator duration.
    */
    'sending' => [
        'gap_min'           => (int) env('WHATSAPP_GAP_MIN', 4),
        'gap_max'           => (int) env('WHATSAPP_GAP_MAX', 12),
        'typing_per_char_ms' => (int) env('WHATSAPP_TYPING_PER_CHAR_MS', 55),
        'typing_min_ms'     => (int) env('WHATSAPP_TYPING_MIN_MS', 900),
        'typing_max_ms'     => (int) env('WHATSAPP_TYPING_MAX_MS', 9000),
    ],

    // Retry backoff (seconds) when a channel is temporarily down. Messages are
    // never dropped — the job releases the message back to 'pending'.
    'retry' => [
        'backoff'      => (int) env('WHATSAPP_RETRY_BACKOFF', 60),
        'max_attempts' => (int) env('WHATSAPP_MAX_ATTEMPTS', 0), // 0 = keep retrying forever
    ],

    /*
    |--------------------------------------------------------------------------
    | Channel health
    |--------------------------------------------------------------------------
    | A WhatsApp-Web (QR) channel reports liveness through its Node bridge
    | heartbeat. If no heartbeat lands within this window the channel is flagged
    | 'disconnected', admins are alerted to re-scan the QR, and pending messages
    | wait safely until it reconnects.
    */
    'health' => [
        'heartbeat_timeout' => (int) env('WHATSAPP_HEARTBEAT_TIMEOUT', 90),
    ],

    /*
    |--------------------------------------------------------------------------
    | Drivers
    |--------------------------------------------------------------------------
    */
    'drivers' => [
        'meta' => \Modules\WhatsApp\Entities\Services\Drivers\MetaCloudDriver::class,
        'web'  => \Modules\WhatsApp\Entities\Services\Drivers\WhatsAppWebDriver::class,
    ],

    // Meta Graph API version for the Cloud API driver.
    'meta' => [
        'graph_version' => env('WHATSAPP_META_GRAPH_VERSION', 'v21.0'),
    ],

    /*
    |--------------------------------------------------------------------------
    | "Powered by" footer
    |--------------------------------------------------------------------------
    | Appended (italic) to every AUTOMATED message/notification when the per-
    | business `powered_by` setting is on (default on). The text is hard-coded
    | here; the on/off switch lives in wa_settings so it can be toggled in the UI
    | or disabled straight from the DB. Manual outbox sends are NOT branded.
    */
    'powered_by_text' => env('WHATSAPP_POWERED_BY_TEXT', 'Powered by TPS'),

    /*
    |--------------------------------------------------------------------------
    | AI cost estimation (USD per 1,000,000 tokens)
    |--------------------------------------------------------------------------
    | Used only to ESTIMATE spend in the AI-usage panel from ai_usage_logs.
    | Approximate list prices — adjust to your provider's current pricing.
    | Matched by the first key found as a substring of the model name.
    */
    'ai_pricing' => [
        'gemini-2.5-flash-lite' => ['in' => 0.075, 'out' => 0.30],
        'gemini-2.5-flash'      => ['in' => 0.15,  'out' => 0.60],
        'gemini-1.5-flash'      => ['in' => 0.075, 'out' => 0.30],
        'gpt-4o-mini'           => ['in' => 0.15,  'out' => 0.60],
        'gpt-4o'                => ['in' => 2.50,  'out' => 10.00],
        'haiku'                 => ['in' => 0.80,  'out' => 4.00],
        'sonnet'                => ['in' => 3.00,  'out' => 15.00],
        'deepseek'              => ['in' => 0.27,  'out' => 1.10],
        'default'               => ['in' => 0.15,  'out' => 0.60],
    ],
];
