<?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('registros', function (Blueprint $table) {
            $table->id();
            $table->string('codigo',15);
            $table->string('documento', 15);
            $table->string('nombres', 90);
            $table->string('apellidos', 90);
            $table->enum('genero', ['M','F'])->default('M');
            $table->date('fecha_nac');
            $table->char('tipo_paciente');
            $table->date('fecha_intervencion')->nullable();
            $table->string('responsable_pago', 255)->nullable();
            $table->enum('status', ['N','P','D'])->default('N');
            $table->integer('nro_factura');
            $table->date('fecha_factura');
            $table->date('fecha_pago')->nullable();
            $table->date('fecha_iq')->nullable();
            $table->text('comentario')->nullable();
            $table->decimal('honorarios_anestesiologo', $precision = 20, $scale = 2)->default(0) ; //monto 1
            $table->decimal('honorarios_anestesiologo_p', $precision = 20, $scale = 2)->default(0); //monto 2
            $table->decimal('honorarios_anestesiologo_total', $precision = 20, $scale = 2)->default(0); //monto 3
            $table->decimal('evaluacion_preanestesica', $precision = 20, $scale = 2)->default(0); //monto 4
            $table->decimal('evaluacion_preanestesica_p', $precision = 20, $scale = 2)->default(0); //monto 5
            $table->decimal('evaluacion_preanestesica_total', $precision = 20, $scale = 2)->default(0); //monto 6
            $table->decimal('monto', $precision = 20, $scale = 2); //monto 7
            $table->decimal('monto_pagado', $precision = 20, $scale = 2); //monto 8
            $table->decimal('monto_diferencia', $precision = 20, $scale = 2); //monto 9
            $table->enum('activo', ['0','1','2'])->default(1);
            $table->bigInteger('tasa_id')->unsigned()->nullable();
            $table->bigInteger('cirujano_id')->unsigned()->nullable();
            $table->bigInteger('anestesiologo_id')->unsigned()->nullable();
            $table->bigInteger('intervencion_id')->unsigned()->nullable();
            $table->timestamps();
            $table->foreign('tasa_id')->references('id')->on('tasas')->onDelete('cascade')->onUpdate('cascade');
            $table->foreign('cirujano_id')->references('id')->on('cirujanos')->onDelete('cascade')->onUpdate('cascade');
            $table->foreign('anestesiologo_id')->references('id')->on('anestesiologos')->onDelete('cascade')->onUpdate('cascade');
            $table->foreign('intervencion_id')->references('id')->on('intervencions')->onDelete('cascade')->onUpdate('cascade');
        });

    }

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