<?php

namespace App\Models;

use CodeIgniter\Model;

class CertificateTrainingModel extends Model
{
    protected $table            = 'certificates_training';
    protected $primaryKey       = 'cert_training_id';
    protected $useAutoIncrement = true;
    protected $returnType       = 'array'; // Bisa diubah ke 'object' jika lebih suka
    
    // Fitur Soft Delete
    protected $useSoftDeletes   = true;
    
    // Field yang boleh diisi (Mass Assignment)
    protected $allowedFields    = ['cert_id', 'contact_id'];

    // Fitur Otomatisasi Timestamp
    protected $useTimestamps    = true;
    protected $dateFormat       = 'datetime';
    protected $createdField     = 'created_at';
    protected $updatedField     = 'updated_at';
    protected $deletedField     = 'deleted_at';

    // Validasi Sederhana
    protected $validationRules      = [
        'cert_id'    => 'required|numeric',
        'contact_id' => 'required|numeric',
    ];
    
    protected $validationMessages   = [
        'cert_id' => [
            'required' => 'ID Sertifikat wajib diisi.',
            'numeric'  => 'ID Sertifikat harus berupa angka.'
        ],
        'contact_id' => [
            'required' => 'ID Contact wajib diisi.',
            'numeric'  => 'ID Contact harus berupa angka.'
        ]
    ];

    protected $skipValidation       = false;

    // /**
    //  * Contoh Method untuk mengambil data training lengkap dengan nama sertifikat dan contact
    //  */
    // public function getTrainingDetails($id = null)
    // {
    //     $builder = $this->db->table($this->table);
    //     $builder->select('Certificates_Training.*, Certificates.cert_name, Contacts.contact_name'); // Asumsi nama tabel Contacts
    //     $builder->join('Certificates', 'Certificates.cert_id = Certificates_Training.cert_id');
    //     $builder->join('Contacts', 'Contacts.contact_id = Certificates_Training.contact_id');
    //     $builder->where('Certificates_Training.deleted_at', null); // Pastikan yang belum dihapus

    //     if ($id) {
    //         return $builder->where('cert_training_id', $id)->get()->getRowArray();
    //     }

    //     return $builder->get()->getResultArray();
    // }
}