<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('cards', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('tenant_id')->comment('테넌트 ID');
            $table->string('card_company', 50)->comment('카드사');
            $table->text('card_number_encrypted')->comment('암호화된 카드번호');
            $table->string('card_number_last4', 4)->comment('카드번호 끝 4자리');
            $table->string('expiry_date', 5)->comment('유효기간 (MM/YY)');
            $table->text('card_password_encrypted')->nullable()->comment('암호화된 비밀번호 앞2자리');
            $table->string('card_name', 100)->comment('카드 별칭');
            $table->string('status', 20)->default('active')->comment('상태: active/inactive');
            $table->unsignedBigInteger('assigned_user_id')->nullable()->comment('담당자 ID');
            $table->unsignedBigInteger('created_by')->nullable()->comment('생성자 ID');
            $table->unsignedBigInteger('updated_by')->nullable()->comment('수정자 ID');
            $table->unsignedBigInteger('deleted_by')->nullable()->comment('삭제자 ID');
            $table->softDeletes();
            $table->timestamps();

            $table->index('tenant_id', 'idx_cards_tenant');
            $table->index('status', 'idx_cards_status');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('cards');
    }
};
