<?php

namespace App\Models;

use CodeIgniter\Model;

class CodeDetailModel extends Model
{
    protected $table         = 'code_detail';
    protected $primaryKey    = 'cd_idx';
    protected $returnType    = 'object';
    protected $useTimestamps = false;
    protected $allowedFields = [
        'cd_ck_idx',
        'cd_code',
        'cd_name',
        'cd_sort',
        'cd_state',
        'cd_regdate',
    ];

    /**
     * 특정 코드 종류의 세부코드 목록
     */
    public function getByKind(int $ckIdx, bool $activeOnly = false): array
    {
        $builder = $this->where('cd_ck_idx', $ckIdx);
        if ($activeOnly) {
            $builder->where('cd_state', 1);
        }
        return $builder->orderBy('cd_sort', 'ASC')->findAll();
    }
}
