<?php

namespace lib\Services;

use lib\Entities\ClientEntity;
use lib\Entities\MemberEntity;
use lib\Entities\OnetimeEntity as Entity;
use lib\Entities\ServiceEntity;
use lib\Http\Request;
use lib\Models\OnetimeModel as Model;

class OnetimeService extends CommonService
{
  public function __construct()
  {
    parent::__construct();
  }
  final public function getClassName(): string
  {
    return "Onetime";
  }
  final public function getClassPath(): string
  {
    return $this->getClassName();
  }
  public function getModelClass(): string
  {
    return Model::class;
  }
  public function getEntityClass(): string
  {
    return Entity::class;
  }

  //도메인쿠폰 사용용
  public function useCouponByService(ServiceEntity $service, ClientEntity $client, MemberEntity $member, string $onetime_case, int $coupon, string $note, string $onetime_request_date): bool
  {
    $formDatas = [
      "client_code"           => $service->getClientCode(),
      "service_code"          => $service->getServiceCode(),
      "onetime_case"          => $onetime_case,
      "onetime_sub"           => "도메인 쿠폰 구매 / {$coupon} 개",
      "onetime_amount"        => 0,
      "onetime_payment"       => 0,
      "onetime_nonpayment"    => 0,
      "onetime_accountStatus" => 'complete',
      "onetime_request_date"  => $onetime_request_date,
      "onetime_payment_date"  => $onetime_request_date,
      "onetime_note"          => trim($note),
      "onetime_handle_date"   => $onetime_request_date,
      "onetime_manager"       => $member->getPK(),
      "client_name"           => $client->getTitle(),
      "server_code"           => $service->getServerCode(),
    ];
    return $this->getModel()->insert($formDatas);
  }
}
