<?php

declare(strict_types=1);

namespace Apexl\Io\Dtos\Relationship\Decorators;

use Apexl\Io\Interfaces\QueryDecorator;
use Apexl\Io\Interfaces\RelationshipInterface;
use Apexl\Vault\Enums\SortDirection;
use Apexl\Vault\Interfaces\QueryBuilderInterface;

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

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