<?php

namespace Gaco\SnapBi\Services\Banks\Mandiri;

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

/**
 * Mandiri Snap API
 */
class MandiriSnapApi implements ServiceInterface
{
    use HasSelfCall;
    use HasVirtualAccount;
    use HasToken;
    use HasTransaction;

    protected ?ConfigInterface $config = null;

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

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

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

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