<?php

namespace Gaco\SnapBi\Services\Banks\Ocbc;

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

/**
 * OCBC Snap API
 * 
 * Main service class for OCBC bank
 * Uses traits to provide different service methods
 */
class OcbcSnapApi implements ServiceInterface
{
    use HasSelfCall;
    use HasVirtualAccount;
    use HasToken;
    use HasTransaction;

    protected ?ConfigInterface $config = null;

    /**
     * Constructor
     * 
     * @param ConfigInterface|null $config Bank config
     */
    public function __construct(?ConfigInterface $config = null)
    {
        $this->config = $config ?? OcbcConfig::call();

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

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

    /**
     * Get response handler (default to Inquiry)
     * 
     * @return \Gaco\SnapBi\Contracts\ResponseInterface
     */
    public function response(): \Gaco\SnapBi\Contracts\ResponseInterface
    {
        return $this->inquiry()->response();
    }
}
