<?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
    {
        Schema::table('item_attributes', function (Blueprint $table): void {
            $table->boolean('show_in_selector')->default(true)->after('sort_order');
        });

        $abonoDateAttributeIds = DB::table('item_attributes')
            ->join('catalog_items', 'catalog_items.id', '=', 'item_attributes.catalog_item_id')
            ->join('attribute', 'attribute.id', '=', 'item_attributes.attribute_id')
            ->where('catalog_items.tenant_code', 'fiesta_futbol_infantil')
            ->where('catalog_items.slug', 'abono')
            ->where('attribute.codigo', 'event_date')
            ->pluck('item_attributes.id');

        DB::table('item_attributes')
            ->whereIn('id', $abonoDateAttributeIds)
            ->update(['show_in_selector' => false]);
    }

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