<?php
	include "../../conn.php";

	header('Content-Type: application/json; charset=utf-8');
	header('Strict-Transport-Security: max-age=31536000');
	header('Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Authorization');
	header('Access-Control-Allow-Credentials: true');

	$origin = isset($_SERVER['HTTP_ORIGIN']) ? $_SERVER['HTTP_ORIGIN'] : '';
	header('Access-Control-Allow-Origin: ' . $origin);
	header('Vary: Origin');

	date_default_timezone_set("Asia/Kolkata");
	$serverTime = date("Y-m-d H:i:s");

	$response = [
		'code' => 11,
		'msg' => 'Method not allowed',
		'msgCode' => 12,
		'serviceNowTime' => $serverTime
	];

	$body = file_get_contents("php://input");
	$post = json_decode($body, true);

	if ($_SERVER['REQUEST_METHOD'] != 'GET') {

		if (
			isset($post['language']) &&
			isset($post['pageNo']) &&
			isset($post['pageSize']) &&
			isset($post['random']) &&
			isset($post['signature']) &&
			isset($post['timestamp'])
		) {

			$language  = mysqli_real_escape_string($conn, $post['language']);
			$pageNo    = mysqli_real_escape_string($conn, $post['pageNo']);
			$pageSize  = mysqli_real_escape_string($conn, $post['pageSize']);
			$random    = mysqli_real_escape_string($conn, $post['random']);
			$signature = mysqli_real_escape_string($conn, $post['signature']);

			$signStr = '{"language":'.$language.',"pageNo":'.$pageNo.',"pageSize":'.$pageSize.',"random":"'.$random.'"}';
			$makeSign = strtoupper(md5($signStr));

			if ($makeSign == $signature) {

				$list = [];
				
				$list[] = [
					'title' => 'tirnga.danzio.shop',
					'siteMessage' => 'Welcome to 𝟖𝟗𝐜𝐥𝐮𝐛 game platform, we will serve you wholeheartedly!',
					'addtime' => '2025-12-24 16:20:00'
				];

				$list[] = [
					'title' => 'Welcome to 𝟖𝟗𝐜𝐥𝐮𝐛 Game',
					'siteMessage' => '𝟖𝟗𝐜𝐥𝐮𝐛 Game ek exciting gaming platform hai jahan fast gameplay aur daily rewards milte hain.',
					'addtime' => '2025-12-24 16:20:00'
				];

				$list[] = [
					'title' => 'Fair Play & Security',
					'siteMessage' => '𝟖𝟗𝐜𝐥𝐮𝐛 Game me fair play system follow hota hai aur sabhi users ka data fully secure rehta hai.',
					'addtime' => '2025-12-24 16:21:00'
				];

				$list[] = [
					'title' => 'New Games Coming Soon',
					'siteMessage' => 'Jald hi 𝟖𝟗𝐜𝐥𝐮𝐛 Game me naye aur exciting games add hone wale hain. Updates ke liye connected rahein!',
					'addtime' => '2025-12-24 16:23:00'
				];

				$list[] = [
					'title' => '24x7 Customer Support',
					'siteMessage' => 'Kisi bhi problem ke liye hamari support team 24x7 aapki madad ke liye available hai.',
					'addtime' => '2025-12-24 16:24:00'
				];

				$response['data']['list'] = $list;
				$response['code'] = 0;
				$response['msg'] = 'Succeed';
				$response['msgCode'] = 0;

				http_response_code(200);
				echo json_encode($response);

			} else {
				$response['code'] = 5;
				$response['msg'] = 'Wrong signature';
				$response['msgCode'] = 3;

				http_response_code(200);
				echo json_encode($response);
			}

		} else {
			$response['code'] = 7;
			$response['msg'] = 'Param is Invalid';
			$response['msgCode'] = 6;

			http_response_code(200);
			echo json_encode($response);
		}

	} else {
		http_response_code(405);
		echo json_encode($response);
	}
?>
