<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    public function up(): void
    {
        Schema::create('emi_cards', function (Blueprint $table) {

            $table->id();

            $table->foreignId('user_id')
                ->constrained('users')
                ->cascadeOnDelete();

            $table->string('card_number', 30)
                ->unique();

            $table->decimal('card_limit', 12, 2)
                ->default(0);

            $table->decimal('available_limit', 12, 2)
                ->default(0);

            $table->date('issued_at')
                ->nullable();

            $table->date('expires_at')
                ->nullable();

            $table->enum('status', [
                'pending',
                'active',
                'blocked',
                'expired',
            ])->default('pending');

            $table->timestamp('activated_at')
                ->nullable();

            $table->timestamps();

            $table->index('status');
            $table->index('user_id');
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('emi_cards');
    }
};