<?php

namespace Planaday\Database\MySQL\QueryBuilding\SQLOperators;

use Planaday\Database\Abstraction\SQLQuery\QueryBuilding\SQLOperators\SQLSubqueryComparisonModifier;
use Planaday\Database\Abstraction\SQLQuery\QueryBuilding\SQLQuery;

class MySQLSubqueryComparisonModifier implements SQLSubqueryComparisonModifier {
	/**
	 * @param SQLQuery $subQuery
	 * @param bool $needsAll if true will apply ALL otherwise ANY
	 */
	public function __construct(
		protected SQLQuery $subQuery,
		protected bool $needsAll
	) {}

	public function toQuery():string {
		$output = $this->needsAll ? 'ALL' : 'ANY';
		$output .= ' (' . $this->subQuery->toQuery() . ')';
		return $output;
	}
}