<?php
header("Content-Type: application/json");

include "./../lib/send_reply_json.php";
include "./../setup/connect_db.php";

$maestroID = $_POST["maestro_id"];
$playerName = $_POST["player_name"];


$playerCount = getPlayerCount($maestroID, $playerName);
if($playerCount === null) {
	set_error_message("등록된 학생이 없습니다.");
	send_result_fail();
	exit;
}

set_data("playerCount", $playerCount);
send_result_success();
exit;

function getPlayerCount($maestroID, $playerName) {
	global $db_conn;

	$query = "
		SELECT COUNT(PlayerID)
		FROM player
		WHERE MaestroID = ? AND AccountType <> 1 AND Name LIKE CONCAT('%', ?, '%')
	";
	$stmt = $db_conn->prepare($query);
	$stmt->bind_param("is", $maestroID, $playerName);
	$stmt->execute();
	$stmt->bind_result($playerCount);
	$stmt->fetch();
	$stmt->close();

	return $playerCount;
}

?>