<?php

namespace App\Controllers\Admin\Customer;

use App\Controllers\Admin\AdminController;
use App\Services\Customer\ClientService;
use App\Services\Customer\ServiceService;
use App\Services\Customer\AccountService;
use App\Services\Customer\CouponService;
use App\Services\Customer\PointService;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface;

abstract class CustomerController extends AdminController
{
    private ?ClientService $_clientService = null;
    private ?ServiceService $_serviceService = null;
    private ?AccountService $_accountService = null;
    private ?CouponService $_couponService = null;
    private ?PointService $_pointService = null;
    public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
    {
        parent::initController($request, $response, $logger);
    }

    final public function getClientService(): ClientService
    {
        if (!$this->_clientService) {
            $this->_clientService = new ClientService($this->request);
        }
        return $this->_clientService;
    }
    final public function getServiceService(): ServiceService
    {
        if (!$this->_serviceService) {
            $this->_serviceService = new ServiceService($this->request);
        }
        return $this->_serviceService;
    }
    final public function getAccountService(): AccountService
    {
        if (!$this->_accountService) {
            $this->_accountService = new AccountService($this->request);
        }
        return $this->_accountService;
    }
    final public function getCouponService(): CouponService
    {
        if (!$this->_couponService) {
            $this->_couponService = new CouponService($this->request);
        }
        return $this->_couponService;
    }
    final public function getPointService(): PointService
    {
        if (!$this->_pointService) {
            $this->_pointService = new PointService($this->request);
        }
        return $this->_pointService;
    }

    protected function getFormFieldOption(string $field, array $options): array
    {
        switch ($field) {
            case 'clientinfo_uid':
                $temps = [];
                foreach ($this->getClientService()->getEntities() as $entity) {
                    $temps[$entity->getPK()] = $entity->getTitle();
                }
                $options[$field] = $temps;
                // dd($options);
                break;
            default:
                $options = parent::getFormFieldOption($field, $options);
                break;
        }
        return $options;
    }
    //Index,FieldForm관련
}
