<?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('staff_profiles', function (Blueprint $table) {
            $table->id();
            $table->string('employee_code', 30)->unique()->index();
            $table->foreignId('user_id')->nullable()->constrained('users')->nullOnDelete();
            $table->string('first_name');
            $table->string('last_name')->nullable();
            $table->string('full_name')->nullable()->index();
            $table->string('mobile', 20)->nullable()->index();
            $table->string('email', 100)->nullable()->index();
            $table->string('gender', 20)->nullable();
            $table->string('designation', 100)->nullable();
            $table->string('specialization', 255)->nullable();
            $table->date('joining_date')->nullable();
            $table->foreignId('branch_id')->constrained('branches')->cascadeOnDelete();
            $table->string('employment_type', 30)->nullable();
            $table->decimal('basic_salary', 12, 2)->nullable();
            $table->string('commission_type', 30)->nullable();
            $table->decimal('commission_value', 10, 2)->nullable();
            $table->string('weekly_off_day', 20)->nullable();
            $table->time('shift_start_time')->nullable();
            $table->time('shift_end_time')->nullable();
            $table->string('status', 20)->default('active')->index();
            $table->string('availability_status', 30)->default('available')->index();
            $table->text('notes')->nullable();
            $table->timestamps();
            $table->softDeletes();

            $table->index(['branch_id', 'status']);
        });
    }

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