<?php

return [
    'name' => 'Vrc',

    /*
    |--------------------------------------------------------------------------
    | Service contract bindings (the anti-corruption layer)
    |--------------------------------------------------------------------------
    |
    | Every interaction between VRC and the ERP core passes through one of
    | these contracts. Exactly ONE implementation is bound per contract:
    | an ERP adapter (delegates to existing ERP functionality — App\Contact,
    | App\Transaction, ProductUtil, TransactionUtil, NotificationUtil, ...) or
    | a VRC-native implementation (only when the ERP genuinely lacks the
    | capability). Swapping a reuse-vs-build decision is a one-line change
    | here — ERP core files are never modified and the module stays portable.
    |
    | NOTE: adapters/contracts are introduced phase-by-phase (see the build
    | spec §10). This array starts empty in Phase 0 and grows as each ERP
    | capability is wired in (contacts → Phase 2, stock/invoice/payment →
    | Phase 7, notifications → Phase 7/11).
    |
    */
    'bindings' => [
        // Phase 1 — foundations (tax engine for totals, audit, media).
        \Modules\Vrc\Services\Contracts\TaxServiceContract::class
            => \Modules\Vrc\Services\Adapters\Erp\ErpTaxService::class,
        \Modules\Vrc\Services\Contracts\AuditServiceContract::class
            => \Modules\Vrc\Services\Adapters\Erp\ErpAuditService::class,
        \Modules\Vrc\Services\Contracts\MediaServiceContract::class
            => \Modules\Vrc\Services\Adapters\Erp\ErpMediaService::class,

        // Phase 2 — customers.
        \Modules\Vrc\Services\Contracts\ContactServiceContract::class
            => \Modules\Vrc\Services\Adapters\Erp\ErpContactService::class,

        // Phase 7 — ERP stock consumption + invoicing.
        \Modules\Vrc\Services\Contracts\StockServiceContract::class
            => \Modules\Vrc\Services\Adapters\Erp\ErpStockService::class,
        \Modules\Vrc\Services\Contracts\InvoiceServiceContract::class
            => \Modules\Vrc\Services\Adapters\Erp\ErpInvoiceService::class,

        // Phase 11 — notifications (comms matrix + reminders).
        \Modules\Vrc\Services\Contracts\NotificationServiceContract::class
            => \Modules\Vrc\Services\Adapters\Erp\ErpNotificationService::class,

        // Phase 5 — ISO 18541 Repair & Maintenance Information. Uses the licensed
        // HTTP provider adapter when VRC_RMI_BASE_URL + VRC_RMI_API_KEY are set;
        // the HTTP adapter itself transparently falls back to the offline stub
        // when unconfigured, so this binding is always safe.
        \Modules\Vrc\Services\Contracts\RepairInfoServiceContract::class
            => env('VRC_RMI_BASE_URL') && env('VRC_RMI_API_KEY')
                ? \Modules\Vrc\Services\Adapters\Http\HttpRepairInfoService::class
                : \Modules\Vrc\Services\Adapters\Stub\StubRepairInfoService::class,
    ],

    /*
    |--------------------------------------------------------------------------
    | ISO 18541 RMI provider (licensed) — env-driven
    |--------------------------------------------------------------------------
    | Set base_url + api_key to enable a commercial provider (TecRMI/HaynesPro/
    | Autodata or any REST gateway). Until then the HTTP adapter delegates to
    | the offline stub. Endpoint paths and the auth header/scheme are overridable
    | to match the provider's API surface.
    */
    'rmi' => [
        'provider'    => env('VRC_RMI_PROVIDER', 'http'),
        'base_url'    => env('VRC_RMI_BASE_URL'),
        'api_key'     => env('VRC_RMI_API_KEY'),
        'timeout'     => (int) env('VRC_RMI_TIMEOUT', 10),
        'auth_header' => env('VRC_RMI_AUTH_HEADER', 'Authorization'),
        'auth_scheme' => env('VRC_RMI_AUTH_SCHEME', 'Bearer'),
        'endpoints'   => [
            'vin_decode' => env('VRC_RMI_EP_VIN', 'vin/decode'),
            'lookup'     => env('VRC_RMI_EP_LOOKUP', 'lookup'),
        ],
    ],

    /*
    |--------------------------------------------------------------------------
    | Repair-order state machine (authoritative transition table)
    |--------------------------------------------------------------------------
    | Built in Phase 4. Listed here so the allowed graph lives in one place.
    | Side states (awaiting_parts, on_hold, estimate_declined, cancelled) are
    | reachable from the active states per the rules in spec §4.3.
    */
    'repair_order' => [
        'initial_status' => 'draft',
        'transitions' => [
            'draft'             => ['scheduled', 'checked_in', 'cancelled'],
            'scheduled'         => ['checked_in', 'cancelled'],
            'checked_in'        => ['awaiting_estimate', 'in_progress', 'on_hold', 'cancelled'],
            'awaiting_estimate' => ['estimate_sent', 'on_hold', 'cancelled'],
            'estimate_sent'     => ['estimate_approved', 'estimate_declined', 'on_hold', 'cancelled'],
            'estimate_approved' => ['in_progress', 'on_hold', 'cancelled'],
            'estimate_declined' => ['awaiting_estimate', 'cancelled'],
            'in_progress'       => ['awaiting_parts', 'quality_check', 'on_hold', 'cancelled'],
            'awaiting_parts'    => ['in_progress', 'on_hold', 'cancelled'],
            'on_hold'           => ['checked_in', 'awaiting_estimate', 'estimate_sent', 'estimate_approved', 'in_progress', 'awaiting_parts', 'cancelled'],
            'quality_check'     => ['in_progress', 'ready_for_pickup'],
            'ready_for_pickup'  => ['invoiced'],
            'invoiced'          => ['completed'],
            'completed'         => [],
            'cancelled'         => [],
        ],
    ],

    /*
    |--------------------------------------------------------------------------
    | Repair-specific settings (defaults)
    |--------------------------------------------------------------------------
    | Persisted per-business in vrc_settings under the vrc.* namespace; these
    | are the fallbacks when nothing is configured. Currency / VAT / timezone /
    | numbering come from ERP business settings — never duplicated here.
    */
    'defaults' => [
        'default_labor_rate'    => 0,
        'estimate_validity_days' => 14,

        /*
        | Source strategy per capability — chosen per-business in the VRC
        | settings screen so the module suits any business strategy:
        |   'native'  → use the repair-scoped vrc_ tables
        |   'erp'     → reuse the ERP capability (quotation / service-products)
        | The bound Service contract reads these to pick its adapter at runtime.
        */
        'estimate_source'        => 'native', // native (vrc_estimates) | erp (ERP quotation)
        'service_catalog_source' => 'native', // native (vrc_services)  | erp (ERP service-products)
        'comms_channel'          => 'sms',    // sms | whatsapp (customer notifications channel)
        'comms_matrix' => [
            'estimate_sent'     => true,
            'ready_for_pickup'  => true,
            'invoice_issued'    => true,
            'payment_received'  => true,
            'appointment_confirmed' => true,
        ],
    ],
];
