<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class CreateStudentCardSettingsTable extends Migration
{
    public function up()
    {
        $this->forge->addField([
            'id'                   => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'auto_increment' => true],
            'front_background'     => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true],
            'back_background'      => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true],
            'school_stamp'         => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true],
            'headmaster_signature' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true],
            'card_validity'        => ['type' => 'VARCHAR', 'constraint' => 100, 'default' => 'Berlaku Selama Menjadi Siswa'],
            'show_qrcode'          => ['type' => 'TINYINT', 'constraint' => 1, 'default' => 1],
            'created_at'           => ['type' => 'DATETIME', 'null' => true],
            'updated_at'           => ['type' => 'DATETIME', 'null' => true],
        ]);
        $this->forge->addPrimaryKey('id');
        $this->forge->createTable('student_card_settings');
        
        // Insert default record
        $this->db->table('student_card_settings')->insert(['id' => 1]);
    }

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