<?php

declare(strict_types=1);

namespace apexl\Io\dto\Relationship\Decorators;

use apexl\Io\interfaces\QueryDecorator;
use apexl\Io\interfaces\RelationshipInterface;
use apexl\Vault\enums\SortDirection;
use apexl\Vault\interfaces\driver;

final readonly class OrderByField implements QueryDecorator
{
    public function __construct(
        public string $field,
        public SortDirection $direction = SortDirection::ASC,
    ) {
    }

    public function decorate(RelationshipInterface $relationship, driver $query): driver
    {
        return $query->orderBy($this->field, $this->direction);
    }
}
