<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;

return new class extends Migration
{
    public function up(): void
    {
        if (DB::getDriverName() === 'sqlite') {
            return;
        }

        DB::statement('ALTER TABLE receipts DROP CONSTRAINT IF EXISTS receipts_emissor_type_identification_check');
        DB::statement('ALTER TABLE receipts DROP CONSTRAINT IF EXISTS receipts_receiver_type_identification_check');

        DB::statement("ALTER TABLE receipts ADD CONSTRAINT receipts_emissor_type_identification_check CHECK (emissor_type_identification IN ('01','02','03','04','05','06'))");
        DB::statement("ALTER TABLE receipts ADD CONSTRAINT receipts_receiver_type_identification_check CHECK (receiver_type_identification IN ('01','02','03','04','05','06'))");
    }

    public function down(): void
    {
        if (DB::getDriverName() === 'sqlite') {
            return;
        }

        DB::statement('ALTER TABLE receipts DROP CONSTRAINT IF EXISTS receipts_emissor_type_identification_check');
        DB::statement('ALTER TABLE receipts DROP CONSTRAINT IF EXISTS receipts_receiver_type_identification_check');

        DB::statement("ALTER TABLE receipts ADD CONSTRAINT receipts_emissor_type_identification_check CHECK (emissor_type_identification IN ('physical','juridical','DIMEX','NITE','foreign','not_taxpayer'))");
        DB::statement("ALTER TABLE receipts ADD CONSTRAINT receipts_receiver_type_identification_check CHECK (receiver_type_identification IN ('physical','juridical','DIMEX','NITE','foreign','not_taxpayer'))");
    }
};
