<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class AddSabtuLiburToCalendarSettings extends Migration
{
    public function up()
    {
        $db = \Config\Database::connect();
        
        // Cek apakah kolom key 'sabtu_libur' sudah ada
        $exists = $db->table('calendar_settings')
                     ->where('key', 'sabtu_libur')
                     ->countAllResults();

        if ($exists === 0) {
            $db->table('calendar_settings')->insert([
                'key'        => 'sabtu_libur',
                'value'      => '0',
                'label'      => 'Hari Sabtu Libur (5 Hari Sekolah)',
                'created_at' => date('Y-m-d H:i:s'),
                'updated_at' => date('Y-m-d H:i:s'),
            ]);
        }
    }

    public function down()
    {
        $db = \Config\Database::connect();
        $db->table('calendar_settings')->where('key', 'sabtu_libur')->delete();
    }
}
