<?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('trading_years', function (Blueprint $table) {
            $table->id(); // auto-incrementing primary key
            $table->unsignedBigInteger('user_id'); // foreign key for user
            $table->string('tradingYear'); // trading year as a string
            $table->date('tradingyear_startdate'); // start date of the trading year
            $table->date('tradingyear_enddate'); // end date of the trading year
            $table->integer('trading_status'); // status of the trading year
            $table->integer('active_trading_year'); // flag for active trading year
            $table->integer('finalise_year'); // flag for finalised year
            $table->date('finalise_date')->nullable(); // finalisation date
            $table->timestamps(); // created_at and updated_at fields

            // Foreign key constraint
            $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');

            // Index for user_id
            $table->index('user_id');
        });
    }

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