<?php

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::create('bet_providers', function (Blueprint $table): void {
            $table->id();
            $table->string('code', 32)->unique();
            $table->string('name', 64);
            $table->boolean('is_enabled')->default(true);
            $table->unsignedInteger('sort_order')->default(0);
            $table->timestamps();
        });

        Schema::table('ticket_items', function (Blueprint $table): void {
            $table->string('provider_code', 32)->default('SG')->after('draw_id');
            $table->string('provider_name', 64)->default('Singapore')->after('provider_code');
            $table->index('provider_code', 'idx_ticket_items_provider_code');
        });

    }

    public function down(): void
    {
        Schema::table('ticket_items', function (Blueprint $table): void {
            $table->dropIndex('idx_ticket_items_provider_code');
            $table->dropColumn(['provider_code', 'provider_name']);
        });

        Schema::dropIfExists('bet_providers');
    }
};
