<?php

declare(strict_types=1);

final class ReminderDecision
{
    public function __construct(
        public bool $send = false,
        public string $level = 'soft',
        public int $score = 0,
        public int $nextDelay = 0,
        public array $reasons = [],
        public array $scores = [],
        public array $scoreReasons = []
    ) {}

    public function allow(): void
    {
        $this->send = true;
    }

    public function deny(string $reason): void
    {
        $this->send = false;
        $this->reasons[] = $reason;
    }

    public function addReason(string $reason): void
    {
        $this->reasons[] = $reason;
    }

    public function addScore(string $name, int $score): void
    {
        $this->scores[$name] = $score;
        $this->score += $score;
    }

    public function setLevel(string $level): void
    {
        $this->level = $level;
    }

    public function setNextDelay(int $seconds): void
    {
        $this->nextDelay = $seconds;
    }

    public function addScoreReason(
        string $name,
        string $reason
    ): void {
        $this->scoreReasons[$name][] = $reason;
    }

    public function getScore(string $name): int
    {
        return $this->scores[$name] ?? 0;
    }

    public function toArray(): array
    {
        return [
            'send' => $this->send,
            'level' => $this->level,
            'score' => $this->score,
            'next_delay' => $this->nextDelay,
            'reasons' => $this->reasons,
            'scores' => $this->scores,
            'score_reasons' => $this->scoreReasons,
        ];
    }
}