<?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('rebate_master', function (Blueprint $table) {
            $table->bigIncrements('Reb_Id');

            $table->string('Reb_Code', 30)->unique();
            $table->string('Reb_Name', 150);

            $table->enum('Reb_Type', ['Percent', 'Fixed', 'FullExempt'])
                  ->default('Percent');

            $table->decimal('Reb_Value', 7, 2);

            $table->string('Eligibility', 255)->nullable();

            $table->unsignedBigInteger('FY_Id')->nullable();

            $table->date('Valid_From')->nullable();
            $table->date('Valid_To')->nullable();

            $table->decimal('Max_Cap', 10, 2)->nullable();

            $table->tinyInteger('Is_Active')->default(1);

            $table->timestamps();
            $table->softDeletes();

            $table->foreign('FY_Id')
                  ->references('FY_Id')
                  ->on('fyear_master')
                  ->onDelete('set null');
        });
    }

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