<?php

namespace Planaday\Database\MySQL\QueryBuilding\SQLOperators;

use Planaday\Database\Abstraction\SQLQuery\QueryBuilding\SQLOperators\SQLOr;
use Planaday\Database\Abstraction\SQLQuery\QueryBuilding\SQLUseInterfaces\SQLCondition;

class MySQLOr implements SQLOr {
	/** @var SQLCondition[] */
	protected array $conditions;

	/**
	 * @param SQLCondition ...$conditions
	 */
	public function __construct(SQLCondition ...$conditions) {
		$this->conditions = $conditions;
	}

	public function addCondition(SQLCondition $condition): void{
		$this->conditions[] = $condition;
	}

	function toConditionQuery(): string {
		$conditionStrings = [];
		foreach ($this->conditions as $condition){
			$conditionStrings[] = $condition->toConditionQuery();
		}

		$output = '(1 = 1)';
		if (count($conditionStrings) >= 1){
			$output = '(' . implode(') OR (', $conditionStrings) . ')';
		}
		return $output;
	}
}