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

// get parameters from client
$command = $_POST["command"];


include "./../lib/json_builder.php";
include "./../lib/connect_db.php";

$jsonBuilder = new JsonBuilder();
$dbConnector = new DBConnector();

$isConnected = $dbConnector->connectDB();
if (!$isConnected) {
	$jsonBuilder->setErrorMessage("DB connection : failed");
	$jsonBuilder->sendResultFail();
	exit;
}


const MAESTRO_ID	= 3;	// 삼화초
const PLAYER_ID		= 35;	// 박지상

if ($command === "deleteWritingRecordAll") {
	include "./db_method_container.php";
	include "./typing_exam_collection.php";

	$typingExam = new TypingExamCollection($dbConnector->getMysqli());
	$typingExam->deleteTypingExamRecordAll(MAESTRO_ID, PLAYER_ID);
	$typingExam->deleteTypingExamHighestRecordAll(MAESTRO_ID, PLAYER_ID);
	// $jsonBuilder->setData("deleteWritingRecordAll", "succeeded");
} elseif ($command === "deleteTypingExamRecordAll") {
	include "./db_method_container.php";
	include "./typing_exam_collection.php";

	$typingExam = new TypingExamCollection($dbConnector->getMysqli());
	$typingExam->deleteTypingExamRecordAll(MAESTRO_ID, PLAYER_ID);
	// $jsonBuilder->setData("deleteTypingExamRecordAll", "succeeded");
} elseif ($command === "deleteTypingExamHighestRecordAll") {
	include "./db_method_container.php";
	include "./typing_exam_collection.php";

	$typingExam = new TypingExamCollection($dbConnector->getMysqli());
	$typingExam->deleteTypingExamHighestRecordAll(MAESTRO_ID, PLAYER_ID);
	// $jsonBuilder->setData("deleteTypingExamHighestRecordAll", "succeeded");
}

$jsonBuilder->sendResultSuccess();
?>