<?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('ndrt_officers', function (Blueprint $table) {
            $table->id();
            
            // Personal Information
            $table->string('first_name');
            $table->string('middle_name')->nullable();
            $table->string('surname');
            $table->enum('id_type', ['ID', 'Passport', 'Staff ID', 'Volunteer ID']);
            $table->string('id_number')->unique();
            $table->enum('gender', ['Male', 'Female']);
            $table->date('date_of_birth');
            $table->string('physical_address')->nullable();
            
            // Location
            $table->enum('location_type', ['HQ', 'Branch']);
            $table->foreignId('branch_id')->nullable()->constrained()->onDelete('set null');
            $table->string('unit')->nullable();
            
            // Photo
            $table->string('photo_path')->nullable();
            
            // Contact Details
            $table->string('phone_1');
            $table->string('phone_2')->nullable();
            $table->string('email')->nullable();
            
            // Emergency Contact
            $table->string('emergency_contact_name');
            $table->string('emergency_contact_relation');
            $table->string('emergency_contact_phone_1');
            $table->string('emergency_contact_phone_2')->nullable();
            $table->text('emergency_contact_address')->nullable();
            
            // Other Details
            $table->enum('blood_group', ['A+', 'A-', 'B+', 'B-', 'O+', 'O-', 'AB+', 'AB-'])->nullable();
            $table->json('languages_spoken')->nullable(); // Array of up to 5 languages
            $table->text('health_conditions')->nullable();
            $table->boolean('has_disability')->default(false);
            $table->text('disability_details')->nullable();
            
            // Education
            $table->enum('education_level', [
                'No formal education',
                'Primary School',
                'Secondary',
                'Certificates',
                'Diplomas',
                'Degrees',
                'Masters',
                'PhD'
            ])->nullable();
            $table->string('area_of_study')->nullable();
            
            // Work Experience (stored as JSON array)
            $table->json('work_experience')->nullable();
            
            // Competencies (stored as JSON array)
            $table->json('competencies')->nullable();
            
            // Facilitator Rating
            $table->decimal('facilitator_rating', 3, 2)->nullable();
            
            // Availability
            $table->boolean('available_for_deployment')->default(true);
            
            // Deployment Count (auto-calculated)
            $table->integer('deployment_count')->default(0);
            
            $table->timestamps();
            $table->softDeletes();
        });
    }

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