<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class CreatePayType extends Migration
{
    public function up()
    {
        // Create the payroll_types table
        $this->forge->addField([
            'paytype_id'           => [
                'type'           => 'INT',
                'constraint'     => 11,
                'unsigned'       => true,
                'auto_increment' => true,
            ],
            'paytype_code'   => [
                'type'       => 'VARCHAR',
                'constraint' => 25,
                'null' => true,
            ],
            'paytype_name'   => [
                'type'       => 'VARCHAR',
                'constraint' => 255,
                'null' => false,
            ],
            'is_monthly'      => [
                'type' => 'TINYINT',
                'constraint' => 1,
                'null' => false,
            ],
            'is_semi_monthly' => [
                'type' => 'TINYINT',
                'constraint' => 1,
                'null' => false,
            ],
            'is_daily'        => [
                'type' => 'TINYINT',
                'constraint' => 1,
                'null' => false,
            ],
            'is_hourly'       => [
                'type' => 'TINYINT',
                'constraint' => 1,
                'null' => false,
            ],

            // Common fields
            'created_at' => [
                'type' => 'DATETIME',
                'null' => true,
            ],
            'created_by' => [
                'type' => 'VARCHAR', 
                'constraint' => '20', 
                'null' => true
            ],
            'updated_at' => [
                'type' => 'DATETIME',
                'null' => true,
            ],
            'updated_by' => [
                'type' => 'VARCHAR', 
                'constraint' => '20', 
                'null' => true
            ],
            'deleted_at' => [
                'type' => 'DATETIME',
                'null' => true,
            ],
        ]);

        $this->forge->addKey('paytype_id', true);
        $this->forge->createTable('pay_type');
    }

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