<?php

namespace Gaco\SnapBi\Services;

use Gaco\SnapBi\Contracts\ServiceInterface;
use Gaco\SnapBi\Contracts\ResponseInterface;
use Gaco\SnapBi\Contracts\ConfigInterface;
use Gaco\SnapBi\Services\Response\AbstractResponse;

abstract class AbstractService implements ServiceInterface
{
    protected AbstractResponse $responseHandler;
    protected ?ConfigInterface $config = null;

    /**
     * Constructor
     * 
     * @param ConfigInterface|null $config Bank config (optional for backward compatibility)
     */
    public function __construct(?ConfigInterface $config = null)
    {
        $this->config = $config;
        $this->responseHandler = $this->createResponseHandler();
    }

    /**
     * Get the response handler for this service
     */
    public function response(): ResponseInterface
    {
        return $this->responseHandler;
    }

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

    /**
     * Create the response handler instance
     * Must be implemented by concrete services
     */
    abstract protected function createResponseHandler(): AbstractResponse;
}

