<?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('employees', function (Blueprint $table) {
            $table->id();
            $table->foreignId('company_id')->constrained()->cascadeOnDelete();
            $table->foreignId('user_id')->nullable()->constrained()->nullOnDelete();
            $table->foreignId('branch_id')->nullable()->constrained()->nullOnDelete();

            $table->string('first_name');
            $table->string('last_name')->nullable();
            $table->string('email')->nullable();
            $table->string('phone', 25)->nullable();
            $table->string('document_number', 50)->nullable();

            $table->string('position')->nullable();           // Estilista, Barbero, Esteticista
            $table->string('photo_path')->nullable();
            $table->text('bio')->nullable();
            $table->string('color', 7)->default('#4f46e5');   // color en agenda

            // Comisiones
            $table->boolean('has_commission')->default(false);
            $table->enum('commission_type', ['percentage', 'fixed'])->nullable();
            $table->decimal('commission_value', 10, 2)->nullable();

            $table->boolean('is_bookable')->default(true);    // recibe reservas
            $table->boolean('is_active')->default(true);
            $table->unsignedInteger('sort_order')->default(0);

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

            $table->index(['company_id', 'is_active', 'is_bookable']);
            $table->index(['company_id', 'branch_id']);
        });
    }

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