<?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', function (Blueprint $table) {
            $table->id();
            $table->foreignId('company_id')->constrained()->cascadeOnDelete();
            $table->string('staff_no')->unique();
            $table->string('full_name');
            $table->string('preferred_name')->nullable();
            $table->string('ic_no')->nullable();
            $table->string('old_ic_no')->nullable();
            $table->string('passport_no')->nullable();
            $table->date('date_of_birth')->nullable();
            $table->string('gender')->nullable();
            $table->string('nationality')->default('Malaysian');
            $table->string('religion')->nullable();
            $table->string('race')->nullable();
            $table->string('marital_status')->nullable();
            $table->string('highest_education')->nullable();
            $table->string('phone')->nullable();
            $table->string('mobile_no')->nullable();
            $table->string('office_no')->nullable();
            $table->string('office_ext')->nullable();
            $table->string('email')->nullable();
            $table->string('personal_email')->nullable();
            $table->string('work_email')->nullable();
            $table->string('address_line1')->nullable();
            $table->string('address_line2')->nullable();
            $table->string('city')->nullable();
            $table->string('state')->nullable();
            $table->string('postcode')->nullable();
            $table->string('country')->default('Malaysia');
            $table->string('photo_url')->nullable();
            $table->string('job_title')->nullable();
            $table->string('job_grade')->nullable();
            $table->string('job_category')->nullable();
            $table->foreignId('department_id')->nullable()->constrained('departments')->nullOnDelete();
            $table->foreignId('unit_id')->nullable()->constrained('units')->nullOnDelete();
            $table->string('employment_type')->nullable();
            $table->string('employment_status')->nullable();
            $table->date('join_date')->nullable();
            $table->date('confirmation_date')->nullable();
            $table->date('contract_start_date')->nullable();
            $table->date('contract_end_date')->nullable();
            $table->decimal('basic_salary', 12, 2)->nullable();
            $table->foreignId('manager_id')->nullable()->constrained('staff')->nullOnDelete();
            $table->foreignId('supervisor_id')->nullable()->constrained('staff')->nullOnDelete();
            $table->string('status')->default('active');
            $table->foreignId('previous_staff_id')->nullable()->constrained('staff')->nullOnDelete();
            $table->foreignId('transferred_to_staff_id')->nullable()->constrained('staff')->nullOnDelete();
            $table->string('self_service_token')->nullable()->unique();
            $table->timestamps();
        });
    }

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