use crate::utils::bytes::NinBytes;
use crate::utils::sha256::IntoHash256;

#[derive(Clone, Copy, Debug, serde::Serialize, serde::Deserialize, PartialEq, Eq, PartialOrd, Ord)]
#[serde(transparent)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
pub struct CollectionId(pub i64);

impl IntoHash256 for CollectionId {
    fn hash_256(&self) -> super::hash::Hash256 {
        "@collection_".hash_256().chain_hash(&self.0.as_bytes())
    }
}

#[cfg(feature = "validator")]
mod validator {
    use super::CollectionId;
    use validator::ValidateRange;

    impl ValidateRange<i64> for CollectionId {
        fn greater_than(&self, max: i64) -> Option<bool> {
            self.0.greater_than(max)
        }

        fn less_than(&self, min: i64) -> Option<bool> {
            self.0.less_than(min)
        }
    }
    impl ValidateRange<CollectionId> for CollectionId {
        fn greater_than(&self, max: CollectionId) -> Option<bool> {
            self.0.greater_than(max.0)
        }

        fn less_than(&self, min: CollectionId) -> Option<bool> {
            self.0.less_than(min.0)
        }
    }
}
