use sqlx::any::AnyValue;
use sqlx::postgres::any::AnyValueKind;


#[derive(Clone, Debug)]
pub struct IdentityType {
    inner: AnyValue,
}

impl IdentityType {
    pub fn new(value: AnyValue) -> Self {
        IdentityType { inner: value }
    }
}

impl From<AnyValue> for IdentityType {
    fn from(value: AnyValue) -> Self {
        IdentityType {
            inner: value,
        }
    }
}

impl From<IdentityType> for i16 {
    fn from(val: IdentityType) -> Self {
        if let AnyValueKind::SmallInt(value) = val.inner.kind {
            return value;
        }
        panic!("IdentityType is not i16")
    }
}

impl From<IdentityType> for i64 {
    fn from(val: IdentityType) -> Self {
        if let AnyValueKind::BigInt(value) = val.inner.kind {
            return value;
        }
        panic!("IdentityType is not i64")
    }
}

impl From<IdentityType> for i32 {
    fn from(val: IdentityType) -> Self {
        if let AnyValueKind::Integer(value) = val.inner.kind {
            return value;
        }
        panic!("IdentityType is not i32")
    }
}

impl From<IdentityType> for f32 {
    fn from(val: IdentityType) -> Self {
        if let AnyValueKind::Real(value) = val.inner.kind {
            return value;
        }
        panic!("IdentityType is not f32")
    }
}

impl From<IdentityType> for f64 {
    fn from(val: IdentityType) -> Self {
        if let AnyValueKind::Double(value) = val.inner.kind {
            return value;
        }
        panic!("IdentityType is not f64")
    }
}

impl From<IdentityType> for String {
    fn from(val: IdentityType) -> Self {
        if let AnyValueKind::Text(value) = val.inner.kind {
            return value.to_string();
        }
        panic!("IdentityType is not String")
    }
}

impl From<IdentityType> for Vec<u8> {
    fn from(val: IdentityType) -> Self {
        if let AnyValueKind::Blob(value) = val.inner.kind {
            return value.to_vec();
        }
        panic!("IdentityType is not u8")
    }
}

