<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;
use App\Models\NavigationMenu;

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

        DB::statement("ALTER TABLE navigation_menus MODIFY COLUMN position ENUM('header','mobile','sticky_bar','footer','top_bar','footer_policies') NOT NULL DEFAULT 'header'");

        // Seed default footer policies if none exist
        if (NavigationMenu::where('position', 'footer_policies')->count() === 0) {
            NavigationMenu::create([
                'name' => 'Privacy Policy',
                'link_url' => '/pages/privacy-policy',
                'position' => 'footer_policies',
                'sort_order' => 0,
                'is_active' => true,
            ]);

            NavigationMenu::create([
                'name' => 'Terms & Conditions',
                'link_url' => '/pages/terms-and-conditions',
                'position' => 'footer_policies',
                'sort_order' => 1,
                'is_active' => true,
            ]);

            NavigationMenu::create([
                'name' => 'Refund Policy',
                'link_url' => '/pages/refund-policy',
                'position' => 'footer_policies',
                'sort_order' => 2,
                'is_active' => true,
            ]);
        }
    }

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

        DB::statement("UPDATE navigation_menus SET position = 'header' WHERE position = 'footer_policies'");
        DB::statement("ALTER TABLE navigation_menus MODIFY COLUMN position ENUM('header','mobile','sticky_bar','footer','top_bar') NOT NULL DEFAULT 'header'");
    }
};
