<?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('hacienda_responses', function (Blueprint $table) {
            $table->id();
            $table->string('receipt_key')->unique();
            $table->unsignedBigInteger('receipt_id');
            $table->enum('hacienda_status', ['accepted', 'rejected']);
            $table->text('hacienda_response_xml')->nullable();
            $table->string('hacienda_response_message')->nullable();
            $table->timestamp('hacienda_response_at')->nullable();
            $table->timestamps();

            $table->index('receipt_id');
            $table->foreign('receipt_id')->references('id')->on('receipts')->onDelete('cascade');
            
        });
    }

    

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