<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class Createscheduleavailabilitytable extends Migration
{
    public function up()
    {
        // Tabel unavailability guru per slot
        $this->forge->addField([
            'id'          => ['type' => 'INT', 'unsigned' => true, 'auto_increment' => true],
            'teacher_id'  => ['type' => 'INT', 'unsigned' => true],
            'day'         => ['type' => 'TINYINT', 'unsigned' => true, 'comment' => '1=Senin...6=Sabtu'],
            'slot_number' => ['type' => 'TINYINT', 'unsigned' => true,
                              'comment' => '0 = kosongkan seluruh hari, >0 = slot jam tertentu'],
            'reason'      => ['type' => 'VARCHAR', 'constraint' => 100, 'null' => true],
            'created_at'  => ['type' => 'DATETIME', 'null' => true],
            'updated_at'  => ['type' => 'DATETIME', 'null' => true],
        ]);
        $this->forge->addKey('id', true);
        $this->forge->addKey(['teacher_id', 'day', 'slot_number'], false, true); // unique
        $this->forge->createTable('schedule_availability', true);
    }

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