<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class CreateClaimBeneficiariesTable extends Migration
{
    public function up()
    {
        $this->forge->addField([
            'id' => [
                'type' => 'INT',
                'constraint' => 11,
                'unsigned' => true,
                'auto_increment' => true,
            ],
            'claim_id' => [
                'type' => 'INT',
                'constraint' => 11,
                'unsigned' => true,
            ],
            'beneficiary_id' => [
                'type' => 'INT',
                'constraint' => 11,
                'unsigned' => true,
            ],
            'amount' => [
                'type' => 'DECIMAL',
                'constraint' => [10, 2],
            ],
            'status' => [
                'type' => 'ENUM',
                'constraint' => ['pending', 'approved', 'paid', 'rejected'],
                'default' => 'pending',
            ],
            'payment_date' => [
                'type' => 'DATETIME',
                'null' => true,
            ],
            'payment_method' => [
                'type' => 'VARCHAR',
                'constraint' => 100,
                'null' => true,
            ],
            'created_at' => [
                'type' => 'DATETIME',
                'null' => true,
            ],
            'updated_at' => [
                'type' => 'DATETIME',
                'null' => true,
            ],
        ]);
        $this->forge->addPrimaryKey('id');
        $this->forge->addForeignKey('claim_id', 'claims', 'id', 'CASCADE', 'CASCADE');
        $this->forge->addForeignKey('beneficiary_id', 'beneficiaries', 'id', 'CASCADE', 'CASCADE');
        $this->forge->createTable('claim_beneficiaries');
    }

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