// 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 MembershipNamespaceUrl {
    #[serde(rename = "https://schema.oparl.org/1.1/Membership")]
    Identifier,
}

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

    use super::MembershipNamespaceUrl;

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

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

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