<?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('employees', function (Blueprint $table) {
            $table->id();

            $table->foreignId('user_id')->constrained()->onDelete('cascade');

            $table->foreignId('designation_id')->nullable()->constrained()->nullOnDelete();

            $table->string('employee_code', 30);
            $table->string('name');
            $table->string('phone', 30)->nullable();
            $table->string('email')->nullable();
            $table->string('photo')->nullable();

            $table->string('father_name')->nullable();
            $table->string('mother_name')->nullable();
            $table->string('nid_no', 50)->nullable();

            $table->text('present_address')->nullable();
            $table->text('permanent_address')->nullable();

            $table->date('joining_date')->nullable();

            $table->enum('employee_type', ['monthly', 'daily_roz'])->default('monthly');

            $table->boolean('overtime_eligible')->default(false);
            $table->decimal('overtime_rate', 12, 2)->default(0);

            $table->decimal('opening_balance', 14, 2)->default(0);

            $table->enum('status', ['active', 'inactive'])->default('active');
            $table->text('note')->nullable();

            $table->timestamps();

            $table->unique(['user_id', 'employee_code']);
            $table->index(['user_id', 'employee_type']);
            $table->index(['user_id', 'status']);
            $table->index(['user_id', 'name']);
            $table->index(['user_id', 'phone']);
        });
    }

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