use std::{net::IpAddr, ops::RangeInclusive};
use chrono::NaiveTime;
use easyfix_messages::fields::FixString;
use serde::{Deserialize, Deserializer};
use tokio::time::Duration;
use crate::session_id::SessionId;
fn duration_from_seconds<'de, D>(deserializer: D) -> Result<Duration, D::Error>
where
D: Deserializer<'de>,
{
Ok(Duration::from_secs(u64::deserialize(deserializer)?))
}
#[derive(Clone, Debug, Deserialize)]
pub struct Settings {
pub host: IpAddr,
pub port: u16,
pub sender_comp_id: FixString,
pub sender_sub_id: Option<FixString>,
#[serde(deserialize_with = "duration_from_seconds")]
pub heartbeat_interval: Duration,
#[serde(deserialize_with = "duration_from_seconds")]
pub auto_disconnect_after_no_logon_received: Duration,
pub auto_disconnect_after_no_heartbeat: u32,
}
#[derive(Clone, Debug, Deserialize)]
pub struct SessionSettings {
pub session_id: SessionId,
pub session_time: RangeInclusive<NaiveTime>,
pub logon_time: RangeInclusive<NaiveTime>,
pub send_redundant_resend_requests: bool,
pub check_comp_id: bool,
pub check_latency: bool,
pub max_latency: Duration,
pub reset_on_logon: bool,
pub reset_on_logout: bool,
pub reset_on_disconnect: bool,
pub refresh_on_logon: bool,
pub sender_default_appl_ver_id: FixString,
pub target_default_appl_ver_id: FixString,
pub enable_next_expected_msg_seq_num: bool,
pub persist: bool,
pub verify_logout: bool,
}