<?php

namespace App\Modules\Lookup\Config;

use App\Facades\Settings;

class AutoTraderConfig extends \Mtc\VehicleValuation\Config\AutoTraderConfig
{
    #[\Override]
    public function enabled(): bool
    {
        return Settings::get('valuation-auto-trader-enabled') ?? false;
    }

    #[\Override]
    public function apiKey(): string
    {
        return $this->usesSalesChannelCredentials()
            ? config('services.auto-trader-ai.api_key')
            : config('services.auto-trader.api_key');
    }

    #[\Override]
    public function apiSecret(): string
    {
        return $this->usesSalesChannelCredentials()
            ? config('services.auto-trader-ai.api_secret')
            : config('services.auto-trader.api_secret');
    }

    #[\Override]
    public function merchantId(): string
    {
        return Settings::get('auto-trader-advertiser-id') ?? '';
    }

    #[\Override]
    public function live(): bool
    {
        return config('services.auto-trader.use_live_api');
    }

    /**
     * When the AutoTrader sales channel is enabled the provider grants lookup
     * access for the dealer against the Connect (AI) credential set rather than
     * the standard lookup credentials. Same API and dealer ID, different keys.
     */
    private function usesSalesChannelCredentials(): bool
    {
        return (bool) Settings::get('sales-channels-auto-trader-enabled', false);
    }
}
