<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class CreateAscImports extends Migration
{
    public function up()
    {
        $this->forge->addField([
            'id' => [
                'type'           => 'INT',
                'constraint'     => 11,
                'unsigned'       => true,
                'auto_increment' => true,
            ],
            'name' => [
                'type'       => 'VARCHAR',
                'constraint' => 100,
                'comment'    => 'Misal: Ganjil 2024/2025',
            ],
            'academic_year' => [
                'type'       => 'VARCHAR',
                'constraint' => 20,
                'comment'    => 'Misal: 2024/2025',
            ],
            'semester' => [
                'type'       => 'ENUM',
                'constraint' => ['Ganjil', 'Genap'],
                'default'    => 'Ganjil',
            ],
            'filename' => [
                'type'       => 'VARCHAR',
                'constraint' => 255,
                'comment'    => 'Nama file XML yang diupload',
            ],
            'is_active' => [
                'type'       => 'TINYINT',
                'constraint' => 1,
                'default'    => 0,
                'comment'    => '1 = jadwal aktif yang ditampilkan',
            ],
            'total_schedules' => [
                'type'       => 'INT',
                'constraint' => 11,
                'default'    => 0,
                'comment'    => 'Total slot jadwal hasil import',
            ],
            'imported_by' => [
                'type'       => 'INT',
                'constraint' => 11,
                'unsigned'   => true,
                'null'       => true,
                'comment'    => 'user_id yang melakukan import',
            ],
            'notes' => [
                'type' => 'TEXT',
                'null' => true,
            ],
            'created_at' => [
                'type' => 'DATETIME',
                'null' => true,
            ],
            'updated_at' => [
                'type' => 'DATETIME',
                'null' => true,
            ],
        ]);

        $this->forge->addKey('id', true);
        $this->forge->addKey('is_active');
        $this->forge->createTable('asc_imports');
    }

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