<?php

use App\Modules\OrderStatus\Repositories\OrderStatusRepository;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('card_orders', function (Blueprint $table) {
            $table->id();

            $table->string('unique_id')->nullable()->unique();

            $table->foreignId('card_state_id')->constrained('card_states')->restrictOnDelete();
            $table->foreignId('card_type_id')->constrained('card_types')->restrictOnDelete();

            $table->string('region', 2)->index();
            $table->foreignId('branch_id')->constrained('branches')->restrictOnDelete();

            $table->string('customer_name')->index();
            $table->string('customer_surname')->index();
            $table->string('customer_patronic_name')->nullable();
            $table->date('born_at')->nullable();
            $table->string('old_surname')->nullable();

            $table->string('citizenship');
            $table->string('passport_serie')->index();
            $table->string('passport_id')->index();
            $table->date('passport_given_at');
            $table->string('passport_given_by');
            $table->string('born_place');

            $table->string('job_location')->nullable();

            $table->string('passport_address')->nullable();
            $table->string('real_address')->nullable();

            $table->string('phone')->nullable()->index();
            $table->string('phone_additional')->nullable()->index();

            $table->string('status')->nullable()->default(OrderStatusRepository::defaultStatus())->index();

            $table->text('passport_one');
            $table->text('passport_two');
            $table->text('passport_three');
            $table->text('passport_four');

            $table->text('notes')->nullable();

            $table->foreignId('user_id')->constrained('users')->restrictOnDelete();

            $table->boolean('paid')->default(false);

            $table->timestamps();
            $table->softDeletes();
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('card_orders');
    }
};
