<?php

declare(strict_types=1);

namespace Autogedal\FeedMonitor\Model;

/**
 * One execution of a monitored job / sub-feed, handed back to FeedMonitor when it ends.
 */
class FeedRun
{
    private bool $finished = false;
    private bool $incompleteAllowed = false;
    private int $rejectedRows = 0;

    public function __construct(
        private readonly int $id,
        private readonly string $jobCode,
        private readonly string $feedCode
    ) {
    }

    /**
     * 0 when the run could not be recorded (the monitor never stops the job).
     */
    public function getId(): int
    {
        return $this->id;
    }

    public function getJobCode(): string
    {
        return $this->jobCode;
    }

    public function getFeedCode(): string
    {
        return $this->feedCode;
    }

    public function getKey(): string
    {
        return MonitorKey::build($this->jobCode, $this->feedCode);
    }

    public function isFinished(): bool
    {
        return $this->finished;
    }

    public function markFinished(): void
    {
        $this->finished = true;
    }

    /**
     * A CLI allowance was used by this run: every "smaller than usual" check of the run lets it through.
     */
    public function isIncompleteAllowed(): bool
    {
        return $this->incompleteAllowed;
    }

    public function markIncompleteAllowed(): void
    {
        $this->incompleteAllowed = true;
    }

    /**
     * Rows of the feed rejected by its format (not used for the update), reported with the result of the run.
     */
    public function getRejectedRows(): int
    {
        return $this->rejectedRows;
    }

    public function setRejectedRows(int $rejectedRows): void
    {
        $this->rejectedRows = $rejectedRows;
    }
}
