use serde::{Deserialize, Serialize};
use serde_repr::{Deserialize_repr, Serialize_repr};
use std::any::{TypeId};
use strum::{Display, EnumString};
use crate::api_responses::{GetDevRealKpiDataInverterItem, GetDevRealKpiDataPowerSensorItem};
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct LoginRequest {
pub user_name: String,
pub system_code: String,
}
impl LoginRequest {
pub fn new(user_name: &str, system_code: &str) -> Self {
Self {
user_name: user_name.to_string(),
system_code: system_code.to_string(),
}
}
}
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct GetStationRealKpiDataRequest {
pub station_codes: String,
}
#[derive(EnumString, Display, Serialize_repr, Deserialize_repr, PartialEq, Debug, Clone)]
#[repr(u8)]
pub enum DeviceType {
StringInverter = 1,
SmartLogger = 2,
TRANSFORMER = 8,
EMI = 9,
ProtocolConverter = 13,
GeneralDevice = 16,
GridMeter = 17,
PID = 22,
PinnetDataLogger = 37,
ResidentialInverter = 38,
Battery = 39,
BackupBox = 40,
PLC = 45,
Optimizer = 46,
PowerSensor = 47,
Dongle = 62,
DistributedSmartLogger = 63,
SafetyBox = 70,
}
impl DeviceType {
pub fn get_data_item_type(&self) -> TypeId {
match self {
DeviceType::ResidentialInverter => TypeId::of::<GetDevRealKpiDataInverterItem>(),
DeviceType::PowerSensor => TypeId::of::<GetDevRealKpiDataPowerSensorItem>(),
_ => todo!(),
}
}
}
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct GetDevRealKpiRequest {
pub dev_ids: String,
pub dev_type_id: DeviceType,
}
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct GetDevListRequest {
pub station_codes: String,
}