<?php

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('schedules', function (Blueprint $table) {
            $table->id();
            $table->foreignId('client_id')->constrained('clients')->onDelete('cascade');
            $table->foreignId('provider_id')->constrained('providers')->onDelete('cascade');
            $table->foreignId('address_id')->constrained('addresses')->onDelete('cascade');
            $table->date('date');
            $table->enum('period_type', ['2', '4', '6', '8']);
            $table->enum('schedule_type', ['default', 'custom'])->default('default');
            $table->time('start_time');
            $table->time('end_time');
            $table->enum('status', ['pending', 'accepted', 'rejected', 'paid', 'cancelled', 'started', 'finished'])->default('pending');
            $table->decimal('total_amount', 10, 2);
            $table->string('code', 4);
            $table->boolean('code_verified')->default(false);
            $table->timestamps();
            $table->softDeletes();

            $table->index('client_id');
            $table->index('provider_id');
            $table->index('address_id');
            $table->index('date');
            $table->index('status');
        });
    }

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