<?php

namespace Planaday\Database\MySQL\QueryBuilding\SQLOperators;

use Planaday\Database\Abstraction\SQLQuery\QueryBuilding\SQLColumn;
use Planaday\Database\Abstraction\SQLQuery\QueryBuilding\SQLOperators\SQLLike;
use Planaday\Platform\PlatformAbstraction\DataHandler;

class MySQLLike implements SQLLike {
	public function __construct(
		protected DataHandler $dataHandler,
		protected SQLColumn $toBeTested,
		protected string $value
	) {}

	function toConditionQuery(): string {
		return $this->toBeTested->getTable() . '.' . $this->toBeTested->getColumn() .
		       ' LIKE ' . "'" . $this->dataHandler->escapeSql("%" . addcslashes($this->value, '_%\\') . "%") . "'";
	}
}