use crate::commands::deploy::DeployStatusResponse;
use reqwest::Client;
use uuid::Uuid;

pub const BASE_BFF_URL: &str = if cfg!(debug_assertions) {
	"http://localhost:8080"
} else {
	"https://api.rezon.ai"
};

pub async fn is_build_completed(http_client: Client, build_id: Uuid) -> bool {
	let build_status_req = http_client.get(format!("{BASE_BFF_URL}/models/deploy_status/{}", build_id)).send().await;

	match build_status_req {
		Ok(res) => {
			// Check to make sure that our request returned a 200
			if !res.status().is_success() {
				return false;
			}

			match res.json::<DeployStatusResponse>().await {
				Ok(res) => res.status == "SUCCESS",
				Err(_) => false,
			}
		}
		Err(_) => false,
	}
}
