<?php

namespace lib\Services;

use lib\Entities\AddDbEntity as Entity;
use lib\Models\AddDbModel as Model;

class AddDbService extends CommonService
{
  private ?Model $_model = null;
  public function __construct()
  {
    parent::__construct();
  }
  final public function getClassName(): string
  {
    return "Adddb";
  }
  final public function getClassPath(): string
  {
    return $this->getClassName();
  }
  protected function getModel(): Model
  {
    if ($this->_model === null) {
      $this->_model = new Model();
      // $this->_model->setDebug(true);
    }
    return $this->_model;
  }

  public function getServiceCodesByCode(string $adddb_code): array
  {
    //AddDBService에서 해당코드의(닷디펜더,딥파인더 등) Service_Code를 가져와서 배열에 저장
    $this->getModel()->select('DISTINCT(service_code) AS service_code');
    $this->getModel()->where('AddDB_code', $adddb_code);
    $service_codes = [];
    foreach ($this->getModel()->getEntitys() as $entity) {
      $service_codes = $entity->getServiceCode();
    }
    return $service_codes;
  }
}
