<?php

namespace App\Controllers\Admin;

use App\Services\BoardService;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface;

class BoardController extends AdminController
{
  public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
  {
    parent::initController($request, $response, $logger);
    $this->content_title = lang("{$this->getService()->getClassName()}.title");
    $this->class_path .= $this->getService()->getClassName();
    // $this->view_path  = '/admin/search';
  }
  public function getService(): BoardService
  {
    if (!$this->_service) {
      $this->_service = new BoardService();
    }
    return $this->_service;
  }

  public function notice(): ResponseInterface
  {
    $this->getService()->setAction(__FUNCTION__);
    $this->getService()->setFormFields();
    //전달값정의
    $this->getService()->setFormDatas($this->request->getGet());
    $formDatas = $this->getSErvice()->getFormDatas();
    return $this->response->setJSON($this->getService()->getLatest(
      array_key_exists('category', $formDatas) && $formDatas['category'] ? $formDatas['category'] : BOARD['CATEGORY']['NOTICE'],
    ));
  }
  public function reqeusttask(): ResponseInterface
  {
    $this->getService()->setAction(__FUNCTION__);
    $this->getService()->setFormFields();
    //전달값정의
    $this->getService()->setFormDatas($this->request->getGet());
    $formDatas = $this->getSErvice()->getFormDatas();
    return $this->response->setJSON($this->getService()->getLatest(
      array_key_exists('category', $formDatas) && $formDatas['category'] ? $formDatas['category'] : BOARD['CATEGORY']['NOTICE'],
      ['worker_uid' => $this->getMyAuth()->getUIDByAuthInfo()]
    ));
  }
}
