<?php

declare(strict_types=1);

namespace App\Framework\Database\Criteria\Expression;

use App\Framework\Database\Criteria\Criterion;

/**
 * Logical expression for combining criteria with AND/OR
 */
final readonly class LogicalExpression implements Criterion
{
    public function __construct(
        public Criterion $left,
        public Criterion $right,
        public string    $operator = 'AND'
    ) {
    }

    public function toSql(): string
    {
        return "({$this->left->toSql()}) {$this->operator} ({$this->right->toSql()})";
    }

    public function getParameters(): array
    {
        return array_merge($this->left->getParameters(), $this->right->getParameters());
    }
}
