use crate::modules::heat_pump::models::{config::HPConfig, state::HPState};
use serde::{Deserialize, Serialize};

#[derive(Debug, Serialize, Deserialize)]
pub struct Mode {
    pub mode: u8,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct ModeResponse {
    pub mode: Option<u8>,
}
impl ModeResponse {
    pub fn new(mode: Option<u8>) -> Self {
        Self { mode }
    }
}

#[derive(Debug, Serialize, Deserialize)]
pub struct StateConfigResponse {
    pub state: HPState,
    pub config: HPConfig,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct ErrorResponse {
    pub message: &'static str,
}
impl ErrorResponse {
    pub fn new(message: &'static str) -> Self {
        Self { message }
    }
}

#[derive(Debug, Serialize, Deserialize, Copy, Clone)]
pub struct HPHeatingConfig {
    /// A.1.6 -> Room floor set temperature, transmission value = °C.
    pub heating_floor_temperature: Option<u8>,
    /// A.1.10 -> Room heating start hysteresis, transmission value = °C.
    pub heating_hysteresis: Option<u8>,
    /// A.1.14 -> 0: automatic control of electric heating in room mode, 1: electric heating in room mode
    pub room_electric_heating_mode: Option<u8>,
}

#[derive(Debug, Serialize, Deserialize, Copy, Clone)]
pub struct HPDefrostConfig {
    /// A.2.1 -> Automatic defrost: defrost into the set temperature, transmission value = °C * 2 +60;
    pub defrost_into_temperature: Option<i8>,
    /// A.2.4 -> 0: automatic mode; 1: manual mode;
    pub defrost_mode: Option<u8>,
    /// A.2.5 -> Defrost Exit the set temperature, transfer value = °C * 2 + 60;
    pub defrost_exit_temperature: Option<i8>,
    /// A.2.6 -> Defrost maximum time, transfer value = min (minutes)
    pub defrost_maximum_time: Option<u8>,
    /// A.2.7 -> Defrost entry cycle set time, transfer value = min (minutes)
    pub defrost_entry_cycle_time: Option<u8>,
}

#[derive(Debug, Serialize, Deserialize, Copy, Clone)]
pub struct HPWaterTankConfig {
    /// A.1.4 -> Water tank temperature setting, transmission value = °C.
    pub water_tank_temperature: Option<u8>,
    /// A.1.9 -> Water tank heating start hysteresis, transmission value = °C;
    pub water_tank_hysteresis: Option<u8>,
}

#[derive(Debug, Serialize, Deserialize, Copy, Clone)]
pub struct HPCoolingConfig {
    /// A.1.8 -> Cooling mode Water temperature setting, transmission value = °C.
    pub cooling_temperature: Option<u8>,
}

#[derive(Debug, Serialize, Deserialize, Copy, Clone)]
pub struct HPGeneralConfig {
    /// A.1.2 -> 1~7 -> the model of the heat pump (what modes it supports etc.) Fixed to 7 (Water tank plus room heating and cooling models)
    pub model: Option<u8>,
    /// A.1.3 -> Outdoor ambient temperature is too low, the shutdown protection temperature setting, transmission value = °C * 2 + 60. Electric heating start cycle temperature setting value(°C*2+60)
    pub shutdown_protection_temperature: Option<i8>,
}
