<?php

namespace Gaco\SnapBi\Services\Banks\Cimb;

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

/**
 * CIMB Snap API
 */
class CimbSnapApi implements ServiceInterface
{
    use HasSelfCall;
    use HasVirtualAccount;
    use HasToken;
    use HasTransaction;

    protected ?ConfigInterface $config = null;

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

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

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

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