<?php

declare(strict_types=1);

namespace App\Framework\Database\Criteria\Expression;

use App\Framework\Database\Criteria\Criterion;

/**
 * LIKE expression for pattern matching
 */
final readonly class LikeExpression implements Criterion
{
    public function __construct(
        public string $property,
        public string $pattern,
        public bool   $caseSensitive = true
    ) {
    }

    public function toSql(): string
    {
        $operator = $this->caseSensitive ? 'LIKE' : 'ILIKE';

        return "{$this->property} {$operator} ?";
    }

    public function getParameters(): array
    {
        return [$this->pattern];
    }
}
