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

$Breed = isset($_POST["bd_Breed"]) ? $_POST["bd_Breed"] : null;
$AgeInWeeks = isset($_POST["bd_Age"]) ? $_POST["bd_Age"] : null;

$response = array(); 

$result = executeQuery($conn, "SELECT Stnd_H_H_per FROM egg_standards WHERE is_deleted = FALSE AND is_current = TRUE AND BreedType = ? AND AgeInWeeks = ?", "ss", [$Breed,$AgeInWeeks]);

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

if ($result->num_rows > 0) {
	while($row = $result->fetch_assoc()) 
	{
		$response["SHH"] = $row["Stnd_H_H_per"];
	}
} else {
	$response["SHH"] = 0;
}

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