<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class CreatePeminjaman extends Migration
{
    public function up()
    {
        $this->forge->addField([

            'id'=>[
                'type'=>'INT',
                'constraint'=>11,
                'unsigned'=>true,
                'auto_increment'=>true
            ],

            'kode_pinjam'=>[
                'type'=>'VARCHAR',
                'constraint'=>30
            ],

            'anggota_id'=>[
                'type'=>'INT',
                'constraint'=>11
            ],

            'buku_id'=>[
                'type'=>'INT',
                'constraint'=>11
            ],

            'tanggal_pinjam'=>[
                'type'=>'DATE'
            ],

            'tanggal_kembali'=>[
                'type'=>'DATE'
            ],

            'status'=>[
                'type'=>'ENUM',
                'constraint'=>['Dipinjam','Dikembalikan'],
                'default'=>'Dipinjam'
            ],

            // 🔥 TAMBAHAN PENTING
            'denda'=>[
                'type'=>'INT',
                'constraint'=>11,
                'default'=>0
            ],

            'created_at'=>[
                'type'=>'DATETIME',
                'null'=>true
            ],

            'updated_at'=>[
                'type'=>'DATETIME',
                'null'=>true
            ]

        ]);

        $this->forge->addKey('id', true);
        $this->forge->createTable('peminjaman');
    }

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