<?php

namespace Planaday\Database\MySQL\QueryBuilding\SQLAggregates;

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

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

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

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

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