<?php

namespace App\Models;

use CodeIgniter\Model;

class TahfidzReportModel extends Model
{
    protected $table            = 'tahfidz_student_reports';
    protected $primaryKey       = 'id';
    protected $useAutoIncrement = true;
    protected $returnType       = 'array';
    protected $useSoftDeletes   = false;
    protected $allowedFields    = [
        'program_id', 'student_id', 'fashahah', 'tajwid', 'adab', 'catatan', 'created_by'
    ];

    protected $useTimestamps = true;
    protected $createdField  = 'created_at';
    protected $updatedField  = 'updated_at';

    public function __construct()
    {
        parent::__construct();
        $this->db->query("
            CREATE TABLE IF NOT EXISTS `tahfidz_student_reports` (
              `id`           BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
              `program_id`   BIGINT UNSIGNED NOT NULL,
              `student_id`   BIGINT UNSIGNED NOT NULL,
              `fashahah`     TINYINT UNSIGNED NOT NULL,
              `tajwid`       TINYINT UNSIGNED NOT NULL,
              `adab`         TINYINT UNSIGNED NOT NULL,
              `catatan`      TEXT NULL,
              `created_by`   BIGINT UNSIGNED NOT NULL,
              `created_at`   DATETIME NULL,
              `updated_at`   DATETIME NULL,
              PRIMARY KEY (`id`),
              UNIQUE KEY `uq_student_program_report` (`program_id`, `student_id`)
            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci
        ");
    }
}
