<?php

declare(strict_types=1);

namespace App\Framework\Database\Criteria;

/**
 * Order specification for sorting results
 */
final class Order
{
    private function __construct(
        public readonly string $property,
        public readonly bool $ascending
    ) {
    }

    public static function asc(string $property): self
    {
        return new self($property, true);
    }

    public static function desc(string $property): self
    {
        return new self($property, false);
    }

    public function toSql(): string
    {
        $direction = $this->ascending ? 'ASC' : 'DESC';

        return "{$this->property} {$direction}";
    }
}
