<?php

namespace Planaday\Database\MySQL\QueryBuilding\SQLAggregates;

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

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

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

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

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