<?php

declare(strict_types=1);

namespace Database\Seeders;

use App\Services\Compliance\IsmsControls;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;

class DefaultIsmsControlsSeeder extends Seeder
{
    public function run(): void
    {
        $now = now();
        $rows = [];

        foreach (IsmsControls::CONTROLS as $code => [$category, $title, $severity]) {
            $rows[] = [
                'code' => $code,
                'category' => $category,
                'title' => $title,
                'description' => null,
                'verifier' => IsmsControls::class.'::check_'.str_replace('.', '_', $code),
                'severity' => $severity,
                'automated' => true,
                'created_at' => $now,
                'updated_at' => $now,
            ];
        }

        DB::table('isms_controls')->upsert($rows, ['code'], [
            'category', 'title', 'verifier', 'severity', 'automated', 'updated_at',
        ]);
    }
}
