<?php

namespace Gaco\SnapBi\Services\Banks\Bca;

use Gaco\SnapBi\Contracts\ServiceInterface;
use Gaco\SnapBi\Contracts\ConfigInterface;
use Gaco\SnapBi\Services\Banks\Bca\Traits\HasVirtualAccount;
use Gaco\SnapBi\Services\Banks\Bca\Traits\HasToken;
use Gaco\SnapBi\Services\Banks\Bca\Traits\HasTransaction;
use Gaco\SnapBi\Services\Config\BcaConfig;
use Gaco\SnapBi\Exceptions\SnapBiException;
use Gaco\SnapBi\Traits\HasSelfCall;

/**
 * BCA Snap API
 */
class BcaSnapApi implements ServiceInterface
{
    use HasSelfCall;
    use HasVirtualAccount;
    use HasToken;
    use HasTransaction;

    protected ?ConfigInterface $config = null;

    public function __construct(?ConfigInterface $config = null)
    {
        $this->config = $config ?? BcaConfig::call();

        if (!$this->config::isRegistered()) {
            throw new SnapBiException(
                "BCA configuration is not registered. " .
                    "Please register it first using: Config::bca([...])"
            );
        }
    }

    public function getConfig(): ConfigInterface
    {
        return $this->config;
    }

    public function response(): \Gaco\SnapBi\Contracts\ResponseInterface
    {
        return $this->inquiry()->response();
    }
}
