use serde::{Deserialize, Serialize};
use crate::types::validate_fields;
use crate::types::{CountryCode, DateTime, Extensions, PartyId, PartyRef, Validate, Validator};
use super::types::Role;
pub use crate::v2_3_0::hub_client_info::ConnectionStatus;
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct ClientInfo {
pub party_id: PartyId,
pub country_code: CountryCode,
pub role: Role,
pub status: ConnectionStatus,
pub last_updated: DateTime,
#[serde(flatten, default, skip_serializing_if = "Extensions::is_empty")]
pub extensions: Extensions,
}
impl ClientInfo {
#[must_use]
pub fn new(party: PartyRef, role: Role, status: ConnectionStatus, last_updated: DateTime) -> Self {
Self {
party_id: party.party_id,
country_code: party.country_code,
role,
status,
last_updated,
extensions: Extensions::new(),
}
}
#[must_use]
pub fn party(&self) -> PartyRef {
PartyRef { country_code: self.country_code.clone(), party_id: self.party_id.clone() }
}
#[must_use]
pub fn is_reachable(&self) -> bool {
self.status == ConnectionStatus::Connected
}
}
impl Validate for ClientInfo {
fn validate_in(&self, v: &mut Validator) {
validate_fields!(self, v, party_id, country_code, role, status, last_updated);
}
}