<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class AddSoalColumnsToAssessments extends Migration
{
    public function up()
    {
        // Jenis soal yang dipakai dalam event ini (ditentukan admin untuk ASTS/ASAS/ASAT, guru untuk ASH)
        $fields = [
            'has_pg'            => ['type' => 'TINYINT', 'constraint' => 1, 'default' => 0, 'after' => 'grade_id'],
            'has_bs'            => ['type' => 'TINYINT', 'constraint' => 1, 'default' => 0, 'after' => 'has_pg'],
            'has_isian'         => ['type' => 'TINYINT', 'constraint' => 1, 'default' => 0, 'after' => 'has_bs'],
            'has_essay'         => ['type' => 'TINYINT', 'constraint' => 1, 'default' => 0, 'after' => 'has_isian'],
            // Mode input isian: 'total' atau 'per_nomor'
            'isian_mode'        => ['type' => 'ENUM', 'constraint' => ['total', 'per_nomor'], 'default' => 'total', 'after' => 'has_essay'],
            'isian_total_soal'  => ['type' => 'SMALLINT', 'default' => 0, 'after' => 'isian_mode'],
            // Mode input essay: 'total' atau 'per_nomor'
            'essay_mode'        => ['type' => 'ENUM', 'constraint' => ['total', 'per_nomor'], 'default' => 'total', 'after' => 'isian_total_soal'],
            'essay_total_soal'  => ['type' => 'SMALLINT', 'default' => 0, 'after' => 'essay_mode'],
        ];

        $this->forge->addColumn('assessments', $fields);
    }

    public function down()
    {
        $this->forge->dropColumn('assessments', [
            'has_pg', 'has_bs', 'has_isian', 'has_essay',
            'isian_mode', 'isian_total_soal',
            'essay_mode', 'essay_total_soal',
        ]);
    }
}