<?php

namespace App\Database\Seeds;

use CodeIgniter\Database\Seeder;

class TempKrsSeeder extends Seeder
{
    public function run()
    {
        $forge = \Config\Database::forge();
        
        // 1. Add dosen_pa_id
        try {
            $forge->addColumn('mahasiswa', [
                'dosen_pa_id' => [
                    'type'       => 'INT',
                    'constraint' => 11,
                    'unsigned'   => true,
                    'null'       => true,
                    'after'      => 'prodi_id'
                ],
            ]);
            echo "Added dosen_pa_id\n";
        } catch (\Exception $e) { echo $e->getMessage() . "\n"; }
        
        // 2. Create krs table
        try {
            $forge->addField([
                'id' => [
                    'type'           => 'INT',
                    'constraint'     => 11,
                    'unsigned'       => true,
                    'auto_increment' => true,
                ],
                'mahasiswa_id' => [
                    'type'       => 'INT',
                    'constraint' => 11,
                    'unsigned'   => true,
                ],
                'tahun_akademik_id' => [
                    'type'       => 'INT',
                    'constraint' => 11,
                    'unsigned'   => true,
                ],
                'status' => [
                    'type'       => 'ENUM',
                    'constraint' => ['Draft', 'Menunggu Persetujuan', 'Disetujui', 'Ditolak'],
                    'default'    => 'Draft',
                ],
                'catatan' => [
                    'type' => 'TEXT',
                    'null' => true,
                ],
                'created_at' => [
                    'type' => 'DATETIME',
                    'null' => true,
                ],
                'updated_at' => [
                    'type' => 'DATETIME',
                    'null' => true,
                ],
            ]);
            $forge->addKey('id', true);
            $forge->createTable('krs', true);
            echo "Created krs\n";
        } catch (\Exception $e) { echo $e->getMessage() . "\n"; }
        
        // 3. Add krs_id to peserta_kelas
        try {
            $forge->addColumn('peserta_kelas', [
                'krs_id' => [
                    'type'       => 'INT',
                    'constraint' => 11,
                    'unsigned'   => true,
                    'null'       => true,
                    'after'      => 'id'
                ],
            ]);
            echo "Added krs_id to peserta_kelas\n";
        } catch (\Exception $e) { echo $e->getMessage() . "\n"; }
        
        echo "Done\n";
    }
}
