<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class Createscheduleloadstable extends Migration
{
    public function up()
    {
        $this->forge->addField([
            'id'                  => ['type' => 'INT', 'unsigned' => true, 'auto_increment' => true],
            'schedule_id'         => ['type' => 'INT', 'unsigned' => true, 'null' => true,
                                      'comment' => 'FK ke tabel schedules (header jadwal), nullable dulu'],
            'academic_year_id'    => ['type' => 'INT', 'unsigned' => true],
            'academic_period_id'  => ['type' => 'INT', 'unsigned' => true],
            'teacher_id'          => ['type' => 'INT', 'unsigned' => true],
            'school_subject_id'   => ['type' => 'INT', 'unsigned' => true,
                                      'comment' => 'FK ke school_subjects (mapel sekolah)'],
            'classroom_id'        => ['type' => 'INT', 'unsigned' => true],
            'hours_per_week'      => ['type' => 'TINYINT', 'unsigned' => true, 'default' => 2,
                                      'comment' => 'Jumlah jam tatap muka per minggu'],
            'max_per_day'         => ['type' => 'TINYINT', 'unsigned' => true, 'default' => 2,
                                      'comment' => 'Maks jam mapel ini dalam 1 hari'],
            'preferred_slot_type' => ['type' => "ENUM('any','pagi','siang')", 'default' => 'any',
                                      'comment' => 'Preferensi waktu mengajar'],
            'notes'               => ['type' => 'VARCHAR', 'constraint' => 200, 'null' => true],
            'created_at'          => ['type' => 'DATETIME', 'null' => true],
            'updated_at'          => ['type' => 'DATETIME', 'null' => true],
        ]);
        $this->forge->addKey('id', true);
        $this->forge->addKey(['academic_year_id', 'academic_period_id']);
        $this->forge->addKey(['teacher_id', 'classroom_id']);
        $this->forge->createTable('schedule_loads', true);
    }

    public function down()
    {
        $this->forge->dropTable('schedule_loads', true);
    }
}