pub mod cid;
pub mod entry;
pub mod hashid;
pub mod id;
pub mod ident;
pub mod optional_id;
pub mod record;
pub mod uid;

#[cfg(feature = "std")]
use thiserror::Error;

#[cfg_attr(feature = "std", derive(Error, Debug))]
pub enum ArmourError {
    #[cfg_attr(feature = "std", error("from bytes error"))]
    FromBytesError,
    #[cfg_attr(feature = "std", error("bytes len error"))]
    BytesLenError,
    #[cfg_attr(feature = "std", error("NonZero is 0"))]
    NonZeroError,
    #[cfg_attr(feature = "std", error("zbase decode error"))]
    ZBaseDecodeError,
    #[cfg_attr(feature = "std", error("unknown error"))]
    UnknownError,
    #[cfg(feature = "std")]
    #[cfg_attr(feature = "std", error(transparent))]
    OtherError(#[from] anyhow::Error),
}

pub type Result<T, E = ArmourError> = core::result::Result<T, E>;

#[test]
fn gen_types() {
    use crate::{
        collections::{ident::DefaultHasher, ident::ID, optional_id::OptionalId},
        Datetime, Duration, Entry, Id, Record, RecordStatus, Uid,
    };
    use rapira::Rapira;
    use serde::Serialize;
    use specta::{export::ts, ts::export};
    use typescript_type_def::{write_definition_file, TypeDef};

    #[derive(TypeDef)]
    struct Api {
        ident: ID<DefaultHasher>,
        id: Id<DefaultHasher>,
        optional: OptionalId<DefaultHasher>,
    }

    #[derive(TypeDef, Serialize, Rapira)]
    struct Value {
        name: String,
        age: u32,
        dt: Datetime,
        speed: Duration,
    }

    impl Record for Value {
        type SelfId = Uid<RecordStatus, DefaultHasher>;
    }

    let mut buf = Vec::new();
    write_definition_file::<_, (Api, Entry<Value>)>(&mut buf, Default::default()).unwrap();
    let s = String::from_utf8(buf).unwrap();

    println!("{s}");

    // let res = export::<ID<DefaultHasher>>();
    // let res = export::<OptionalId<DefaultHasher>>();
    // let res = export::<Id<DefaultHasher>>();
    // println!("{res:?}");
    // assert!(res.is_ok());
    // ts("./types.ts");
}
