<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class CreateAttendanceSummary extends Migration
{
    public function up()
    {
        $this->forge->addField([
            'attlogsum_id' => [
                'type' => 'INT',
                'constraint' => 11,
                'unsigned' => true,
                'auto_increment' => true,
            ],
            'paytrans_id' => [
                'type' => 'INT',
                'constraint' => 11,
                'unsigned' => true,
            ],
            'pay_group_id' => [
                'type' => 'INT',
                'constraint' => 11,
                'unsigned' => true,
                'null' => false,
            ],
            'employee_id' => [
                'type' => 'INT',
                'constraint' => 11,
                'unsigned' => true,
            ],
            'company_issued_id' => [
                'type' => 'VARCHAR',
                'constraint' => 25,
            ],
            'employee_name' => [
                'type' => 'VARCHAR',
                'constraint' => 255,
            ],
            'att_work_days' => [
                'type' => 'DECIMAL',
                'constraint' => '12,4',
                '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('attlogsum_id', true);
        $this->forge->addForeignKey('paytrans_id', 'pay_trans', 'paytrans_id', 'CASCADE', 'RESTRICT');
        $this->forge->addForeignKey('pay_group_id', 'pay_group', 'pay_group_id', 'CASCADE', 'RESTRICT');
        $this->forge->createTable('att_log_summary');
    }

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