<?php

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

return new class extends Migration
{
    /**
     * Ficha clínica/estética del cliente. Una por cliente por empresa.
     * Campos sensibles se cifran a nivel de modelo (cast 'encrypted').
     */
    public function up(): void
    {
        Schema::create('clinical_histories', function (Blueprint $table) {
            $table->id();
            $table->uuid('uuid')->unique();
            $table->foreignId('company_id')->constrained()->cascadeOnDelete();
            $table->foreignId('customer_id')->constrained()->cascadeOnDelete();

            // Antecedentes (cifrados)
            $table->text('allergies')->nullable();
            $table->text('diseases')->nullable();
            $table->text('current_medications')->nullable();
            $table->text('previous_procedures')->nullable();
            $table->text('contraindications')->nullable();
            $table->text('skin_sensitivity')->nullable();
            $table->text('special_conditions')->nullable();
            $table->text('medical_notes')->nullable();

            // Ficha estética / técnica
            $table->string('skin_type', 50)->nullable();      // grasa, seca, mixta, sensible
            $table->string('hair_type', 50)->nullable();
            $table->string('current_color', 100)->nullable();
            $table->text('formulas_used')->nullable();
            $table->text('treatments_done')->nullable();
            $table->text('initial_diagnosis')->nullable();
            $table->text('treatment_evolution')->nullable();
            $table->text('internal_notes')->nullable();

            // Auditoría
            $table->foreignId('created_by')->nullable()->constrained('users')->nullOnDelete();
            $table->foreignId('updated_by')->nullable()->constrained('users')->nullOnDelete();

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

            $table->unique(['company_id', 'customer_id']);
        });
    }

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