<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class Addslottypetoscheduetimeslots extends Migration
{
    public function up()
    {
        // Tambah kolom slot_type
        $this->forge->addColumn('schedule_timeslots', [
            'slot_type' => [
                'type'       => "ENUM('kbm','istirahat','upacara','keagamaan','lainnya')",
                'default'    => 'kbm',
                'after'      => 'is_break',
            ],
        ]);

        // Migrasi data lama: is_break=1 → slot_type='istirahat'
        $this->db->query("UPDATE schedule_timeslots SET slot_type = 'istirahat' WHERE is_break = 1");

        // Hapus kolom is_break (sudah tidak dipakai)
        $this->forge->dropColumn('schedule_timeslots', 'is_break');
    }

    public function down()
    {
        // Kembalikan is_break
        $this->forge->addColumn('schedule_timeslots', [
            'is_break' => [
                'type'    => 'TINYINT',
                'constraint' => 1,
                'default' => 0,
                'after'   => 'end_time',
            ],
        ]);

        $this->db->query("UPDATE schedule_timeslots SET is_break = 1 WHERE slot_type = 'istirahat'");

        $this->forge->dropColumn('schedule_timeslots', 'slot_type');
    }
}