<?php

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

return new class extends Migration
{
    public function up(): void
    {
        DB::statement("ALTER TABLE invoices MODIFY type VARCHAR(30) NOT NULL DEFAULT 'tax_invoice'");
        DB::statement("ALTER TABLE invoices MODIFY status VARCHAR(20) NOT NULL DEFAULT 'draft'");

        Schema::table('invoices', function (Blueprint $table) {
            $table->date('payment_date')->nullable()->after('paid_amount');
        });
    }

    public function down(): void
    {
        Schema::table('invoices', function (Blueprint $table) {
            $table->dropColumn('payment_date');
        });

        DB::statement("ALTER TABLE invoices MODIFY type ENUM('tax_invoice','bill_of_supply','export','non_gst') NOT NULL DEFAULT 'tax_invoice'");
        DB::statement("ALTER TABLE invoices MODIFY status ENUM('draft','sent','paid','partial','cancelled') NOT NULL DEFAULT 'draft'");
    }
};
