<?php
require_once("dbconn.php");
require_once("phpFunctions.php");

$data_id = isset($_GET["data_id"]) ? $_GET["data_id"] : null;

$response = array();

$result = executeQuery($conn, "SELECT * FROM batch_details WHERE id = ?", "i", [$data_id]);

if ($result === false) { 
	throw new Exception("Error executing query: " . $conn->error);
} 

if ($result->num_rows > 0) {
	while($row = $result->fetch_assoc()) 
	{
		$response["id"] = $row["id"];
		$response["BatchCode"] = $row["BatchCode"];
		$response["BatchName"] = $row["BatchName"];
		$response["BatchName_switch"] = $row["BatchName_switch"];
		$response["BldgNo"] = $row["BldgNo"];
		$response["CheckInDate"] = $row["CheckInDate"];
		$response["Breed"] = $row["Breed"];
		$response["HenHoused"] = $row["HenHoused"];
		$response["Prod_Previous"] = $row["Prod_Previous"];
		
		// START EGGSIZE
		$response["prev_JMB"] = $row["prev_JMB"];
		$response["prev_XLR"] = $row["prev_XLR"];
		$response["prev_LRG"] = $row["prev_LRG"];
		$response["prev_MED"] = $row["prev_MED"];
		$response["prev_SML"] = $row["prev_SML"];
		$response["prev_PUL"] = $row["prev_PUL"];
		$response["prev_PWE"] = $row["prev_PWE"];
		$response["prev_SPW"] = $row["prev_SPW"];
		$response["prev_B1"] = $row["prev_B1"];
		$response["prev_B2"] = $row["prev_B2"];
		$response["prev_B3"] = $row["prev_B3"];
		$response["prev_M_Dirty"] = $row["prev_M_Dirty"];
		$response["prev_B_Dirty"] = $row["prev_B_Dirty"];
		// END EGGSIZE
		
		$response["Status"] = $row["Status"];
	}
} 

if (empty($response)) {
	echo json_encode(["status" => "error", "message" => "bdepRowData - An error occurred while processing your request."]);
} else {
    echo json_encode($response);
}
?>