<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;
use CodeIgniter\Database\RawSql;

class CreateTeacherSubmissionNotificationHistory extends Migration
{
    public function up()
    {
        $this->forge->addField([
            'id' => [
                'type' => 'INT',
                'unsigned' => true,
                'auto_increment' => true,
            ],
            'teacher_id' => [
                'type' => 'INT',
                'unsigned' => true,
                'null' => false,
            ],
            'class_section_id' => [
                'type' => 'INT',
                'unsigned' => true,
                'null' => false,
            ],
            'admin_id' => [
                'type' => 'INT',
                'unsigned' => true,
                'null' => false,
            ],
            'notification_category' => [
                'type' => 'VARCHAR',
                'constraint' => 64,
                'default' => 'teacher_submissions',
            ],
            'message' => [
                'type' => 'TEXT',
                'null' => true,
            ],
            'status' => [
                'type' => 'VARCHAR',
                'constraint' => 32,
                'default' => 'sent',
            ],
            'school_year' => [
                'type' => 'VARCHAR',
                'constraint' => 32,
                'null' => true,
            ],
            'semester' => [
                'type' => 'VARCHAR',
                'constraint' => 32,
                'null' => true,
            ],
            'sent_at' => [
                'type' => 'DATETIME',
                'null' => false,
                'default' => new RawSql('CURRENT_TIMESTAMP'),
            ],
        ]);

        $this->forge->addKey('id', true);
        $this->forge->addKey(['teacher_id', 'class_section_id']);
        $this->forge->createTable('teacher_submission_notification_history');
    }

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