<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class CreateAcademicPeriodsTable extends Migration
{
    public function up()
    {
        $this->forge->addField([
            'id'               => ['type' => 'BIGINT', 'unsigned' => true, 'auto_increment' => true],
            'academic_year_id' => ['type' => 'BIGINT', 'unsigned' => true],
            'semester'         => ['type' => 'ENUM', 'constraint' => ['Ganjil', 'Genap']],
            'is_active'        => ['type' => 'TINYINT', 'constraint' => 1, 'default' => 0],
            'start_date'       => ['type' => 'DATE', 'null' => true],
            'end_date'         => ['type' => 'DATE', 'null' => true],
            'created_at'       => ['type' => 'DATETIME', 'null' => true],
            'updated_at'       => ['type' => 'DATETIME', 'null' => true],
            'deleted_at'       => ['type' => 'DATETIME', 'null' => true],
        ]);
        $this->forge->addPrimaryKey('id');
        $this->forge->addForeignKey('academic_year_id', 'academic_years', 'id', 'CASCADE', 'CASCADE');
        $this->forge->createTable('academic_periods');
    }

    public function down()
    {
        $this->forge->dropTable('academic_periods');
    }
}