<?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::table('salaries', function (Blueprint $table) {
            // Stats
            $table->integer('working_days')->default(0)->after('year');
            $table->integer('lop_days')->default(0)->after('working_days');

            // Earnings
            $table->decimal('hra', 15, 2)->default(0)->after('base_salary');
            $table->decimal('special_allowance', 15, 2)->default(0)->after('hra');
            $table->decimal('conveyance', 15, 2)->default(0)->after('special_allowance');
            $table->decimal('medical', 15, 2)->default(0)->after('conveyance');
            $table->decimal('lta', 15, 2)->default(0)->after('medical');
            $table->decimal('gross_earnings', 15, 2)->default(0)->after('lta');

            // Deductions
            $table->decimal('esic_employee', 15, 2)->default(0)->after('gross_earnings');
            $table->decimal('esic_employer', 15, 2)->default(0)->after('esic_employee');
            $table->decimal('gratuity', 15, 2)->default(0)->after('esic_employer');
            $table->decimal('prof_tax', 15, 2)->default(0)->after('gratuity');
            $table->decimal('income_tax', 15, 2)->default(0)->after('prof_tax');
            $table->decimal('gross_deductions', 15, 2)->default(0)->after('income_tax');

            // Final Pay Components
            $table->decimal('expense_reimbursements', 15, 2)->default(0)->after('gross_deductions');
            $table->decimal('net_pay', 15, 2)->default(0)->after('expense_reimbursements');
        });
    }

    public function down(): void
    {
        Schema::table('salaries', function (Blueprint $table) {
            $table->dropColumn([
                'working_days', 'lop_days', 'hra', 'special_allowance', 'conveyance',
                'medical', 'lta', 'gross_earnings', 'esic_employee', 'esic_employer',
                'gratuity', 'prof_tax', 'income_tax', 'gross_deductions',
                'expense_reimbursements', 'net_pay'
            ]);
        });
    }
};
