<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    public function up(): void
    {
        Schema::create('guardians', function (Blueprint $table) {
            $table->id();
            $table->uuid('uuid')->unique();
            $table->foreignId('academy_id')->constrained('academies');
            $table->foreignId('person_id')->constrained('people');
            $table->foreignId('user_id')->nullable()->constrained('users')->nullOnDelete();
            $table->string('relationship_type', 30);
            $table->string('occupation')->nullable();
            $table->string('workplace')->nullable();
            $table->boolean('can_pickup')->default(true);
            $table->boolean('is_emergency_contact')->default(false);
            $table->boolean('is_financial_responsible')->default(true);
            $table->text('notes')->nullable();
            $table->timestamps();
        });

        DB::statement("ALTER TABLE guardians ADD CONSTRAINT guardians_relationship_type_check CHECK (relationship_type IN ('father', 'mother', 'grandfather', 'grandmother', 'uncle', 'aunt', 'sibling', 'legal_guardian', 'other'))");
    }

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