<?php

namespace Planaday\Database\MySQL\QueryBuilding;

use Planaday\Database\Abstraction\SQLQuery\QueryBuilding\SQLTable;
use Planaday\Database\Abstraction\SQLQuery\QueryBuilding\SQLColumn;
use Planaday\Database\Abstraction\SQLQuery\SQLFactory;

class MySQLTable implements SQLTable {
	public function __construct(
		protected string $table,
		protected SQLFactory $factory,
		protected ?string $alias = null
	){}

	public function getColumn(string $columnName): SQLColumn {
		return $this->factory->column( $columnName, $this->alias ?? $this->table);
	}

	function toSelectQuery(): string {
		return $this->table . '.*';
	}

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

	function getFromQuery():string {
		return $this->table . (isset($this->alias) ? ' AS ' . $this->alias : '');
	}
}