<?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('account_bills', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('user_id')->comment('用户ID');
            $table->foreign('user_id')->references('uid')->on('member')->onDelete('cascade');
            $table->foreignId('family_id')->nullable()->constrained('account_families')->onDelete('set null')->comment('家庭ID');
            $table->enum('type', ['income', 'expense'])->default('expense')->comment('类型：income-收入，expense-支出');
            $table->decimal('amount', 10, 2)->comment('金额');
            $table->string('category', 50)->comment('分类');
            $table->string('remark')->nullable()->comment('备注');
            $table->date('bill_date')->comment('账单日期');
            $table->timestamps();
            $table->softDeletes();

            $table->index('user_id');
            $table->index('family_id');
            $table->index('type');
            $table->index('bill_date');
        });
    }

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