<?php

namespace App\Models\DTO\Movie;
use JsonSerializable;

class ListParams implements JsonSerializable
{
    public string $key;

    public function __construct(
        public int|null $curPage = null,
        public int $itemPerPage = 10,
        public string|null $movieNm = "",
        public string|null $directorNm = null,
        public string|null $openStartDt = null,
        public string|null $openEndDt = null,
        public string|null $prdtStartYear = null,
        public string|null $prdtEndYear = null,
        public string|null $repNationCd = null,
        public string|null $movieTypeCd = null
    ) {
        $this->key = KOBIS_API_1;
    }

    public function jsonSerialize(): array
    {
        return [
            'curPage' => $this->curPage,
            'itemPerPage' => $this->itemPerPage,
            'movieNm' => $this->movieNm,
            'directorNm' => $this->directorNm,
            'openStartDt' => $this->openStartDt,
            'openEndDt' => $this->openEndDt,
            'prdtStartYear' => $this->prdtStartYear,
            'prdtEndYear' => $this->prdtEndYear,
            'repNationCd' => $this->repNationCd,
            'movieTypeCd' => $this->movieTypeCd
        ];
    }

    public function toArray(): array
    {
        return [
            'key' => $this->key,
            'curPage' => $this->curPage,
            'itemPerPage' => $this->itemPerPage,
            'movieNm' => $this->movieNm,
            'directorNm' => $this->directorNm,
            'openStartDt' => $this->openStartDt,
            'openEndDt' => $this->openEndDt,
            'prdtStartYear' => $this->prdtStartYear,
            'prdtEndYear' => $this->prdtEndYear,
            'repNationCd' => $this->repNationCd,
            'movieTypeCd' => $this->movieTypeCd
        ];
    }

    public function toJson(): string|false
    {
        return json_encode([
            'curPage' => $this->curPage,
            'itemPerPage' => $this->itemPerPage,
            'movieNm' => $this->movieNm,
            'directorNm' => $this->directorNm,
            'openStartDt' => $this->openStartDt,
            'openEndDt' => $this->openEndDt,
            'prdtStartYear' => $this->prdtStartYear,
            'prdtEndYear' => $this->prdtEndYear,
            'repNationCd' => $this->repNationCd,
            'movieTypeCd' => $this->movieTypeCd
        ]);
    }
}
