<?php

namespace Planaday\Database\MySQL\QueryBuilding\SQLAggregates;

use Planaday\Database\Abstraction\SQLQuery\QueryBuilding\SQLAggregates\SQLMin;
use Planaday\Database\Abstraction\SQLQuery\QueryBuilding\SQLColumn;

class MySQLMin implements SQLMin {
	public function __construct(
		protected SQLColumn $column,
		protected ?string $alias = null
	) {}

	function toSelectQuery(): string {
		return 'MIN(' . $this->column->getFullColumnIdentifier() . ')' . (isset($this->alias) ? ' AS ' . $this->alias : '');
	}

	function setAlias( string $alias ): void{
		$this->alias = $alias;
	}

	function getCompareIdentifier(): string {
		return 'MIN(' . $this->column->getFullColumnIdentifier() . ')';
	}
}