<?php

declare(strict_types=1);

namespace apexl\Io\dto;

use apexl\dto\Dto;
use apexl\Io\interfaces\LoaderConditionInterface;
use apexl\Vault\enums\WhereType;
use apexl\Vault\interfaces\ConditionType;
use apexl\Vault\interfaces\driver;

final readonly class LoaderConditionRaw extends Dto implements LoaderConditionInterface
{
    public function __construct(
        public string $condition,
        public array $parameters,
        public ConditionType $type = WhereType::AND,
        private bool $shouldWrap = true,
    ) {}

    public function applyToQuery(driver $query): driver
    {
        if ($this->type === WhereType::OR) {
            return $query->orWhereRaw($this->condition, $this->parameters);
        }

        return $query->whereRaw($this->condition, $this->parameters);
    }

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