use super::*; use crate::mapper::*; impl SpacetimeClient { pub async fn create_square_hole_agent_session( &self, input: SquareHoleAgentSessionCreateRecordInput, ) -> Result { let procedure_input = SquareHoleAgentSessionCreateInput { session_id: input.session_id, owner_user_id: input.owner_user_id, seed_text: input.seed_text, welcome_message_id: input.welcome_message_id, welcome_message_text: input.welcome_message_text, config_json: input.config_json, created_at_micros: input.created_at_micros, }; self.call_after_connect( "create_square_hole_agent_session", move |connection, sender| { connection .procedures() .create_square_hole_agent_session_then(procedure_input, move |_, result| { let mapped = result .map_err(|error| SpacetimeClientError::Procedure(error.to_string())) .and_then(map_square_hole_agent_session_procedure_result); send_once(&sender, mapped); }); }, ) .await } pub async fn get_square_hole_agent_session( &self, session_id: String, owner_user_id: String, ) -> Result { let procedure_input = SquareHoleAgentSessionGetInput { session_id, owner_user_id, }; self.call_after_connect( "get_square_hole_agent_session", move |connection, sender| { connection.procedures().get_square_hole_agent_session_then( procedure_input, move |_, result| { let mapped = result .map_err(|error| SpacetimeClientError::Procedure(error.to_string())) .and_then(map_square_hole_agent_session_procedure_result); send_once(&sender, mapped); }, ); }, ) .await } pub async fn submit_square_hole_agent_message( &self, input: SquareHoleAgentMessageSubmitRecordInput, ) -> Result { let procedure_input = SquareHoleAgentMessageSubmitInput { session_id: input.session_id, owner_user_id: input.owner_user_id, user_message_id: input.user_message_id, user_message_text: input.user_message_text, submitted_at_micros: input.submitted_at_micros, }; self.call_after_connect( "submit_square_hole_agent_message", move |connection, sender| { connection .procedures() .submit_square_hole_agent_message_then(procedure_input, move |_, result| { let mapped = result .map_err(|error| SpacetimeClientError::Procedure(error.to_string())) .and_then(map_square_hole_agent_session_procedure_result); send_once(&sender, mapped); }); }, ) .await } pub async fn finalize_square_hole_agent_message( &self, input: SquareHoleAgentMessageFinalizeRecordInput, ) -> Result { let procedure_input = SquareHoleAgentMessageFinalizeInput { session_id: input.session_id, owner_user_id: input.owner_user_id, assistant_message_id: input.assistant_message_id, assistant_reply_text: input.assistant_reply_text, config_json: input.config_json, progress_percent: input.progress_percent, stage: input.stage, updated_at_micros: input.updated_at_micros, error_message: input.error_message, }; self.call_after_connect( "finalize_square_hole_agent_message_turn", move |connection, sender| { connection .procedures() .finalize_square_hole_agent_message_turn_then( procedure_input, move |_, result| { let mapped = result .map_err(|error| SpacetimeClientError::Procedure(error.to_string())) .and_then(map_square_hole_agent_session_procedure_result); send_once(&sender, mapped); }, ); }, ) .await } pub async fn compile_square_hole_draft( &self, input: SquareHoleCompileDraftRecordInput, ) -> Result { let procedure_input = SquareHoleDraftCompileInput { session_id: input.session_id, owner_user_id: input.owner_user_id, profile_id: input.profile_id, author_display_name: input.author_display_name, game_name: input.game_name, summary_text: input.summary_text, tags_json: input.tags_json, cover_image_src: input.cover_image_src, compiled_at_micros: input.compiled_at_micros, }; self.call_after_connect("compile_square_hole_draft", move |connection, sender| { connection.procedures().compile_square_hole_draft_then( procedure_input, move |_, result| { let mapped = result .map_err(|error| SpacetimeClientError::Procedure(error.to_string())) .and_then(map_square_hole_agent_session_procedure_result); send_once(&sender, mapped); }, ); }) .await } pub async fn update_square_hole_work( &self, input: SquareHoleWorkUpdateRecordInput, ) -> Result { let procedure_input = SquareHoleWorkUpdateInput { profile_id: input.profile_id, owner_user_id: input.owner_user_id, game_name: input.game_name, theme_text: input.theme_text, twist_rule: input.twist_rule, summary_text: input.summary_text, tags_json: input.tags_json, cover_image_src: input.cover_image_src, background_prompt: input.background_prompt, background_image_src: input.background_image_src, shape_options_json: input.shape_options_json, hole_options_json: input.hole_options_json, shape_count: input.shape_count, difficulty: input.difficulty, updated_at_micros: input.updated_at_micros, }; self.call_after_connect("update_square_hole_work", move |connection, sender| { connection.procedures().update_square_hole_work_then( procedure_input, move |_, result| { let mapped = result .map_err(|error| SpacetimeClientError::Procedure(error.to_string())) .and_then(map_square_hole_work_procedure_result); send_once(&sender, mapped); }, ); }) .await } pub async fn publish_square_hole_work( &self, profile_id: String, owner_user_id: String, published_at_micros: i64, ) -> Result { let procedure_input = SquareHoleWorkPublishInput { profile_id, owner_user_id, published_at_micros, }; self.call_after_connect("publish_square_hole_work", move |connection, sender| { connection.procedures().publish_square_hole_work_then( procedure_input, move |_, result| { let mapped = result .map_err(|error| SpacetimeClientError::Procedure(error.to_string())) .and_then(map_square_hole_work_procedure_result); send_once(&sender, mapped); }, ); }) .await } pub async fn list_square_hole_works( &self, owner_user_id: String, ) -> Result, SpacetimeClientError> { self.list_square_hole_works_with_input(SquareHoleWorksListInput { owner_user_id, published_only: false, }) .await } pub async fn list_square_hole_gallery( &self, ) -> Result, SpacetimeClientError> { self.read_after_connect("list_square_hole_gallery", move |connection| { let mut items = connection .db() .square_hole_gallery_view() .iter() .collect::>(); items.sort_by(|left, right| { right .updated_at_micros .cmp(&left.updated_at_micros) .then_with(|| left.profile_id.cmp(&right.profile_id)) }); Ok(items .into_iter() .map(map_square_hole_gallery_view_row) .collect()) }) .await } async fn list_square_hole_works_with_input( &self, procedure_input: SquareHoleWorksListInput, ) -> Result, SpacetimeClientError> { self.call_after_connect("list_square_hole_works", move |connection, sender| { connection.procedures().list_square_hole_works_then( procedure_input, move |_, result| { let mapped = result .map_err(|error| SpacetimeClientError::Procedure(error.to_string())) .and_then(map_square_hole_works_procedure_result); send_once(&sender, mapped); }, ); }) .await } pub async fn get_square_hole_work_detail( &self, profile_id: String, owner_user_id: String, ) -> Result { let procedure_input = SquareHoleWorkGetInput { profile_id, owner_user_id, }; self.call_after_connect("get_square_hole_work_detail", move |connection, sender| { connection.procedures().get_square_hole_work_detail_then( procedure_input, move |_, result| { let mapped = result .map_err(|error| SpacetimeClientError::Procedure(error.to_string())) .and_then(map_square_hole_work_procedure_result); send_once(&sender, mapped); }, ); }) .await } pub async fn delete_square_hole_work( &self, profile_id: String, owner_user_id: String, ) -> Result, SpacetimeClientError> { let procedure_input = SquareHoleWorkDeleteInput { profile_id, owner_user_id, }; self.call_after_connect("delete_square_hole_work", move |connection, sender| { connection.procedures().delete_square_hole_work_then( procedure_input, move |_, result| { let mapped = result .map_err(|error| SpacetimeClientError::Procedure(error.to_string())) .and_then(map_square_hole_works_procedure_result); send_once(&sender, mapped); }, ); }) .await } pub async fn start_square_hole_run( &self, input: SquareHoleRunStartRecordInput, ) -> Result { let procedure_input = SquareHoleRunStartInput { run_id: input.run_id, owner_user_id: input.owner_user_id, profile_id: input.profile_id, started_at_ms: input.started_at_ms, }; self.call_after_connect("start_square_hole_run", move |connection, sender| { connection.procedures().start_square_hole_run_then( procedure_input, move |_, result| { let mapped = result .map_err(|error| SpacetimeClientError::Procedure(error.to_string())) .and_then(map_square_hole_run_procedure_result); send_once(&sender, mapped); }, ); }) .await } pub async fn get_square_hole_run( &self, run_id: String, owner_user_id: String, ) -> Result { let procedure_input = SquareHoleRunGetInput { run_id, owner_user_id, }; self.call_after_connect("get_square_hole_run", move |connection, sender| { connection .procedures() .get_square_hole_run_then(procedure_input, move |_, result| { let mapped = result .map_err(|error| SpacetimeClientError::Procedure(error.to_string())) .and_then(map_square_hole_run_procedure_result); send_once(&sender, mapped); }); }) .await } pub async fn drop_square_hole_shape( &self, input: SquareHoleRunDropRecordInput, ) -> Result { let client_event_id = input.client_event_id.clone(); let procedure_input = SquareHoleRunDropInput { run_id: input.run_id, owner_user_id: input.owner_user_id, hole_id: input.hole_id, client_snapshot_version: input.client_snapshot_version, client_event_id: input.client_event_id, dropped_at_ms: input.dropped_at_ms, }; self.call_after_connect("drop_square_hole_shape", move |connection, sender| { connection.procedures().drop_square_hole_shape_then( procedure_input, move |_, result| { let mapped = result .map_err(|error| SpacetimeClientError::Procedure(error.to_string())) .and_then(map_square_hole_drop_shape_procedure_result) .map(|mut confirmation| { if confirmation.accepted { confirmation.run.last_confirmed_action_id = Some(client_event_id); } confirmation }); send_once(&sender, mapped); }, ); }) .await } pub async fn stop_square_hole_run( &self, input: SquareHoleRunStopRecordInput, ) -> Result { let procedure_input = SquareHoleRunStopInput { run_id: input.run_id, owner_user_id: input.owner_user_id, stopped_at_ms: input.stopped_at_ms, }; self.call_after_connect("stop_square_hole_run", move |connection, sender| { connection .procedures() .stop_square_hole_run_then(procedure_input, move |_, result| { let mapped = result .map_err(|error| SpacetimeClientError::Procedure(error.to_string())) .and_then(map_square_hole_run_procedure_result); send_once(&sender, mapped); }); }) .await } pub async fn restart_square_hole_run( &self, input: SquareHoleRunRestartRecordInput, ) -> Result { let procedure_input = SquareHoleRunRestartInput { source_run_id: input.source_run_id, next_run_id: input.next_run_id, owner_user_id: input.owner_user_id, restarted_at_ms: input.restarted_at_ms, }; self.call_after_connect("restart_square_hole_run", move |connection, sender| { connection.procedures().restart_square_hole_run_then( procedure_input, move |_, result| { let mapped = result .map_err(|error| SpacetimeClientError::Procedure(error.to_string())) .and_then(map_square_hole_run_procedure_result); send_once(&sender, mapped); }, ); }) .await } pub async fn finish_square_hole_time_up( &self, input: SquareHoleRunTimeUpRecordInput, ) -> Result { let procedure_input = SquareHoleRunTimeUpInput { run_id: input.run_id, owner_user_id: input.owner_user_id, finished_at_ms: input.finished_at_ms, }; self.call_after_connect("finish_square_hole_time_up", move |connection, sender| { connection.procedures().finish_square_hole_time_up_then( procedure_input, move |_, result| { let mapped = result .map_err(|error| SpacetimeClientError::Procedure(error.to_string())) .and_then(map_square_hole_run_procedure_result); send_once(&sender, mapped); }, ); }) .await } }