// SPDX-FileCopyrightText: Politik im Blick developers
// SPDX-FileCopyrightText: Wolfgang Silbermayr <wolfgang@silbermayr.at>
//
// SPDX-License-Identifier: AGPL-3.0-or-later OR EUPL-1.2

#[derive(
    Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, serde::Serialize, serde::Deserialize,
)]
pub enum OParlVersion {
    #[serde(rename = "https://schema.oparl.org/1.1/")]
    Version1_1,
}

#[cfg(test)]
mod serde_tests {
    use pretty_assertions::assert_eq;
    use serde_json::json;

    use super::OParlVersion;

    #[test]
    fn serialize() {
        assert_eq!(
            json!(OParlVersion::Version1_1),
            json!("https://schema.oparl.org/1.1/")
        );
    }

    #[test]
    fn deserialize_good() {
        let deserialized: OParlVersion =
            serde_json::from_value(json!("https://schema.oparl.org/1.1/"))
                .expect("value must be deserializable as OParlVersion");
        assert_eq!(deserialized, OParlVersion::Version1_1);
    }

    #[test]
    fn deserialize_bad() {
        assert!(
            serde_json::from_value::<OParlVersion>(json!("https://schema.opral.org/1.1/")).is_err()
        );
        assert!(
            serde_json::from_value::<OParlVersion>(json!("https://schema.oparl.org/1.0/")).is_err()
        );
        assert!(
            serde_json::from_value::<OParlVersion>(json!("https://schema.oparl.org/1.1")).is_err()
        );
        assert!(
            serde_json::from_value::<OParlVersion>(json!("http://schema.oparl.org/1.1/")).is_err()
        );
    }
}
