<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('earnings_summary', function (Blueprint $table) {
            $table->id('earnings_summary_id')->comment('売上集計ID');
            $table->unsignedInteger('park_id')->comment('駐輪場ID');
            $table->string('summary_type', 255)->nullable()->comment('集計区分');
            $table->date('summary_start_date')->nullable()->comment('集計開始日');
            $table->date('summary_end_date')->nullable()->comment('集計終了日');
            $table->date('earnings_date')->nullable()->comment('売上日');
            $table->unsignedInteger('psection_id')->nullable()->comment('車種区分ID');
            $table->string('usertype_subject1', 255)->nullable()->comment('規格');
            $table->unsignedInteger('enable_months')->nullable()->comment('期間(月数)');
            $table->unsignedInteger('regular_new_count')->nullable()->comment('期間件数');
            $table->decimal('regular_new_amount', 10, 2)->nullable()->comment('期間金額');
            $table->unsignedInteger('regular_new_reduction_count')->nullable()->comment('期間成免件数');
            $table->decimal('regular_new_reduction_amount', 10, 2)->nullable()->comment('期間成免金額');
            $table->unsignedInteger('regular_update_count')->nullable()->comment('更新件数');
            $table->decimal('regular_update_amount', 10, 2)->nullable()->comment('更新金額');
            $table->unsignedInteger('regular_update_reduction_count')->nullable()->comment('更新成免件数');
            $table->decimal('regular_update_reduction_amount', 10, 2)->nullable()->comment('更新成免金額');
            $table->unsignedInteger('turnsum_count')->nullable()->comment('残金件数');
            $table->decimal('turnsum', 10, 2)->nullable()->comment('残金');
            $table->decimal('refunds', 10, 2)->nullable()->comment('解時返戻金');
            $table->decimal('other_income', 10, 2)->nullable()->comment('分別収入');
            $table->decimal('other_spending', 10, 2)->nullable()->comment('分別支出');
            $table->unsignedInteger('reissue_count')->nullable()->comment('発行件数');
            $table->decimal('reissue_amount', 10, 2)->nullable()->comment('発行金額');
            $table->text('summary_note')->nullable()->comment('計備考');
            $table->datetime('created_at')->nullable()->comment('登録日時');
            $table->datetime('updated_at')->nullable()->comment('更新日時');
            $table->unsignedInteger('operator_id')->nullable()->comment('新法・ページID');
            
            // インデックス
            $table->index(['park_id', 'earnings_date'], 'idx_park_earnings_date');
            $table->index(['psection_id'], 'idx_psection');
            $table->index(['earnings_date'], 'idx_earnings_date');
        });
    }

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