<?php
namespace database\migrations;

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('sent_receipts', function (Blueprint $table) {
            $table->id();
            $table->string('receipt_type');
            $table->string('ui_key')->unique()->nullable();
            $table->string('consecutive_number');
            $table->dateTime('emission_date');
            $table->dateTime('sent_to_hacienda_at')->nullable();
            $table->enum('hacienda_status',['pending','accepted','rejected'])->default('pending');
            $table->enum('receipt_status',['pending','sent','accepted','rejected'])->default('pending');
            $table->longText('signed_xml')->nullable();
            $table->timestamps();

            $table->string('reception_message')->nullable();
            $table->enum('reception_status',['pending','accepted','partially_accepted','rejected'])->default('pending');
            $table->string('reception_code');
            $table->string('economic_activity_code')->nullable();
            $table->string('tax_condition_code')->nullable();
            $table->string('tax_credited')->nullable();
            $table->decimal('total_expense', 15, 3)->nullable();
            $table->decimal('tax_amount', 15, 3)->nullable();
            $table->decimal('total_voucher', 15, 3);


            $table->string('emissor_name');
            $table->string('emissor_number');
            $table->enum('emissor_type_identification',['physical','juridical','DIMEX','NITE','foreign','not_taxpayer']);
            $table->string('receiver_name')->nullable();
            $table->string('receiver_number')->nullable();
            $table->enum('receiver_type_identification',['physical','juridical','DIMEX','NITE','foreign','not_taxpayer'])->nullable();
            
            
            
            $table->index('consecutive_number');
            $table->index('ui_key');
            $table->index('hacienda_status');

        });
    }

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