use serde::{Deserialize, Serialize, Serializer};

#[derive(Deserialize)]
pub struct CsvAccount {
    #[serde(rename = "Code")]
    pub code: String,
    #[serde(rename = "Description")]
    pub description: Option<String>,
    #[serde(rename = "Type")]
    pub account_type: String,
    #[serde(rename = "CostOutput")]
    pub cost_output: Option<String>,
    #[serde(rename = "PercentFixed")]
    pub percent_fixed: f64,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct CsvCost {
    #[serde(rename = "ACCOUNT")]
    pub account: String,
    #[serde(rename = "COSTCENTRE")]
    pub department: String,
    #[serde(serialize_with = "round_serialize")]
    pub value: f64,
}

fn round_serialize<S>(x: &f64, s: S) -> Result<S::Ok, S::Error>
where
    S: Serializer,
{
    s.serialize_f64((x * 100000.).round() / 100000.)
}