use crate::StringSearchFilter;
// use this type alias to allow for defaults while also allowing to specify a different type in case the type changes
type UserId = aspiesolutions_entity::user::Id;
#[cfg_attr(feature = "rocket", derive(rocket::FromForm))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct CreateUserForm<'r> {
    name: &'r str,
}

impl<'r> CreateUserForm<'r> {
    pub fn new() -> Self {
        Self { name: "" }
    }
    pub fn set_name(mut self, str: &'r str) -> Self {
        self.name = str;
        self
    }
    pub fn name(&'r self) -> &'r str {
        self.name
    }
}
#[cfg_attr(feature = "rocket", derive(rocket::FromForm))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct CreateOrUpdateUserFormData<'r, Id=UserId> {
    id: Option<Id>,
    name: &'r str,
}
#[cfg_attr(feature = "rocket", derive(rocket::FromForm))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct CreateOrUpdateUserForm<'r, Id=UserId> {
    #[cfg_attr(feature = "serde", serde(borrow))]
    user: CreateOrUpdateUserFormData<'r, Id>,
}

#[cfg_attr(feature = "rocket", derive(rocket::FromForm))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]

pub struct UpdateUserForm<'r, Id=UserId> {
    id: Id,
    name: &'r str,
}
impl<'r, Id> UpdateUserForm<'r, Id> {
    pub fn id(&'r self) -> &'r Id {
        &self.id
    }
    pub fn name(&'r self) -> &'r str {
        &self.name
    }
}

#[cfg_attr(feature = "rocket", derive(rocket::FromForm))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]

pub struct DeleteUserForm<Id=UserId> {
    id: Vec<Id>,
    cascade_on_delete: bool,
}
impl<Id> DeleteUserForm<Id> {
    pub fn get_ids<'a>(&'a self) -> &'a Vec<Id> {
        self.id.as_ref()
    }
    pub fn do_cascade_on_delete<'a>(&'a self) -> &'a bool {
        &self.cascade_on_delete
    }
}
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "rocket", derive(rocket::FromForm))]
pub struct UserSearchFormData<'r> {
    #[cfg_attr(feature = "serde", serde(borrow))]
    name: StringSearchFilter<'r>,
}
impl<'r> UserSearchFormData<'r> {
    pub fn name(&'r self) -> &'r StringSearchFilter<'r> {
        &self.name
    }
}

#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "rocket", derive(rocket::FromForm))]

pub struct UserSearchForm<'r> {
    #[cfg_attr(feature = "serde", serde(borrow))]
    user: Option<UserSearchFormData<'r>>,
    page: Option<u32>,
    limit: Option<u16>,
}
impl<'r> UserSearchForm<'r> {
    pub fn user(&'r self) -> Option<&'r UserSearchFormData<'r>> {
        self.user.as_ref()
    }
    pub fn limit(&'r self) -> Option<&'r u16> {
        self.limit.as_ref()
    }
    pub fn page(&'r self) -> Option<&'r u32> {
        self.page.as_ref()
    }
}
