<?php

use Daylight\Core\Models\Enums\PublishStatus;
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::table('pages', function (Blueprint $blueprint) {
            $blueprint->tinyInteger('status')->default(PublishStatus::PUBLISHED->value)->after('id');
        });

        Schema::table('brands', function (Blueprint $blueprint) {
            $blueprint->tinyInteger('status')->default(PublishStatus::PUBLISHED->value)->after('id');
        });

        Schema::table('labels', function (Blueprint $blueprint) {
            $blueprint->tinyInteger('status')->default(PublishStatus::PUBLISHED->value)->after('id');
        });

        Schema::table('attributes', function (Blueprint $blueprint) {
            $blueprint->tinyInteger('status')->default(PublishStatus::PUBLISHED->value)->after('id');
        });

        Schema::table('customer_groups', function (Blueprint $blueprint) {
            $blueprint->tinyInteger('status')->default(PublishStatus::PUBLISHED->value)->after('id');
        });

        Schema::table('menus', function (Blueprint $blueprint) {
            $blueprint->tinyInteger('status')->default(PublishStatus::PUBLISHED->value)->after('id');
        });
    }

    public function down(): void
    {
        $tables = [
            'pages',
            'brands',
            'labels',
            'attributes',
            'customer_groups',
            'menus',
        ];

        foreach ($tables as $table) {
            if (Schema::hasTable($table) && Schema::hasColumn($table, 'status')) {
                Schema::table($table, function (Blueprint $blueprint) {
                    $blueprint->dropColumn('status');
                });
            }
        }
    }
};
