<?php

namespace Database\Seeders;

use App\Models\Event;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;

class EventSeeder extends Seeder
{
    /**
     * Run the database seeds.
     */
    public function run(): void
    {
        // Seed the new decision event type(s)
        // Use query builder to satisfy legacy NOT NULL "options" column
        $rows = [
            [
                'key' => 'add_segment',
                'name' => 'Add segment',
                'description' => 'Activates a target segment for a contract and deactivates previous ones.',
            ],
            [
                'key' => 'archive_contract',
                'name' => 'Archive contract',
                'description' => 'Runs ArchiveExecutor for the activity\'s contract using a specified ArchiveSetting.',
            ],
            [
                'key' => 'end_field_job',
                'name' => 'End field job',
                'description' => 'Dispatches a queued job to finalize field-related processing (implementation-specific).',
            ],
            [
                'key' => 'add_call_later',
                'name' => 'Klic kasneje',
                'description' => 'Ustvari zapis za povratni klic ob določenem datumu in uri.',
            ],
        ];

        foreach ($rows as $row) {
            DB::table('events')->updateOrInsert(
                ['key' => $row['key']],
                [
                    'name' => $row['name'],
                    'description' => $row['description'],
                    'active' => true,
                    'config' => json_encode([]),
                    'options' => json_encode([]),
                    'updated_at' => now(),
                    'created_at' => now(),
                ]
            );
        }
    }
}
