use crate::schema::*;
use diesel::prelude::*;

#[derive(Debug, Clone, Copy, serde::Serialize, serde::Deserialize, PartialEq, Eq)]
pub struct UserID(pub i32);

#[derive(Queryable, Debug, Clone, serde::Serialize)]
pub struct User {
    id: i32,
    pub mail: String,
    pub name: String,
    pub time_create: i64,
    pub time_update: i64,
}

impl User {
    pub fn id(&self) -> UserID {
        UserID(self.id)
    }
}

#[derive(Insertable)]
#[diesel(table_name = users)]
pub struct NewUser<'a> {
    pub time_create: i64,
    pub time_update: i64,
    pub name: &'a str,
    pub mail: &'a str,
}
