<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class CreateCoursesTable extends Migration
{
    public function up()
    {
        $this->forge->addField([
            'id' => [
                'type'           => 'INT',
                'constraint'     => 11,
                'unsigned'       => true,
                'auto_increment' => true,
            ],
            'course_code' => [
                'type'       => 'VARCHAR',
                'constraint' => '100',
            ],
            'course_type' => [
                'type'       => 'VARCHAR',
                'constraint' => '20',
                'default'    => 'modular', // 'modular' or 'one_shot'
            ],
            'module_name' => [
                'type'       => 'VARCHAR',
                'constraint' => '255',
                'null'       => true,
            ],
            'module_order' => [
                'type'    => 'INT',
                'default' => 1,
            ],
            'lesson_title' => [
                'type'       => 'VARCHAR',
                'constraint' => '255',
            ],
            'lesson_order' => [
                'type'    => 'INT',
                'default' => 1,
            ],
            'youtube_url' => [
                'type'       => 'VARCHAR',
                'constraint' => '500',
                'null'       => true,
            ],
            'duration' => [
                'type'       => 'VARCHAR',
                'constraint' => '20',
                'null'       => true,
            ],
            'notes' => [
                'type' => 'TEXT',
                'null' => true,
            ],
            'created_at datetime default current_timestamp',
        ]);
        $this->forge->addKey('id', true);
        $this->forge->createTable('courses');
    }

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