<?php

declare(strict_types=1);

namespace BotGuard\Models;

use BotGuard\Core\Model;

/**
 * Score bands (human/suspicious/bot) and their configured actions.
 */
final class Threshold extends Model
{
    protected string $table = 'thresholds';

    /**
     * @return array<string, array<string, mixed>> keyed by band
     */
    public function map(): array
    {
        $out = [];
        foreach ($this->all() as $row) {
            $out[(string) $row['band']] = $row;
        }

        return $out;
    }

    public function updateBand(string $band, int $minScore, string $action): int
    {
        return $this->db->update(
            $this->table,
            ['min_score' => $minScore, 'action' => $action],
            ['band' => $band]
        );
    }
}
