<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class CreateCompetitions extends Migration
{
    public function up()
    {
        $this->forge->addField([
            'id'               => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'auto_increment' => true],
            'title'            => ['type' => 'VARCHAR', 'constraint' => 150],
            'semester'         => ['type' => 'VARCHAR', 'constraint' => 30, 'null' => true],
            'school_year'      => ['type' => 'VARCHAR', 'constraint' => 20, 'null' => true],
            'class_section_id' => ['type' => 'INT', 'constraint' => 11, 'null' => true],
            'start_date'       => ['type' => 'DATE', 'null' => true],
            'end_date'         => ['type' => 'DATE', 'null' => true],
            'winners_count'    => ['type' => 'INT', 'constraint' => 11, 'default' => 3],
            'prize_per_point'  => ['type' => 'DECIMAL', 'constraint' => '10,2', 'default' => 1],
            'is_published'     => ['type' => 'TINYINT', 'constraint' => 1, 'default' => 0],
            'published_at'     => ['type' => 'DATETIME', 'null' => true],
            'created_by'       => ['type' => 'INT', 'constraint' => 11, 'null' => true],

            'created_at'       => ['type' => 'DATETIME', 'null' => true],
            'updated_at'       => ['type' => 'DATETIME', 'null' => true],
            'deleted_at'       => ['type' => 'DATETIME', 'null' => true],
        ]);

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

    public function down()
    {
        $this->forge->dropTable('competitions', true);
    }
}
