<?php

declare(strict_types=1);

namespace App\Domain\Shared\Application\Query;

use App\Domain\Shared\Domain\Contract\QueryInterface;
use App\Domain\Shared\Domain\Model\JobStatus;

readonly class ListJobsQuery implements QueryInterface
{
    /**
     * @param JobStatus[] $statuses
     */
    public function __construct(
        public ?array $statuses = null,
        public ?string $type = null,
        public ?\DateTimeImmutable $createdAfter = null,
        public ?\DateTimeImmutable $createdBefore = null,
        public ?int $page = 1,
        public ?int $limit = 20,
        public ?string $sortBy = 'createdAt',
        public ?string $sortOrder = 'DESC'
    ) {
        if ($this->page < 1) {
            throw new \InvalidArgumentException('Page must be greater than 0');
        }
        if ($this->limit < 1) {
            throw new \InvalidArgumentException('Limit must be greater than 0');
        }
    }

    public function getOffset(): int
    {
        return ($this->page - 1) * $this->limit;
    }
}
