<?php

namespace Planaday\Database\MySQL\QueryBuilding\SQLAggregates;

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

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

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

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

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