<?php

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

return new class extends Migration
{
    public function up(): void
    {
        if (! DB::table('ticket_statuses')->where('slug', 'merged')->exists()) {
            $maxSort = (int) DB::table('ticket_statuses')->max('sort_order');
            DB::table('ticket_statuses')->insert([
                'name' => 'Birleştirildi',
                'slug' => 'merged',
                'color' => '#6c757d',
                'is_closed' => true,
                'is_default' => false,
                'is_system' => true,
                'scope' => 'closed',
                'sort_order' => $maxSort + 1,
                'status' => true,
                'created_at' => now(),
                'updated_at' => now(),
            ]);
        }
    }

    public function down(): void
    {
        DB::table('ticket_statuses')->where('slug', 'merged')->delete();
    }
};
