use super::Load;
use crate::stmt::{Expr, IntoExpr, IntoInsert, List, Path};
use toasty_core::schema::app::{self, FieldId, ModelId, ModelSet};
pub trait Model: Load<Output = Self> + Sized {
type Query<T>;
type Create: Default + IntoInsert<Model = Self> + IntoExpr<Self>;
type Update<'a>;
type UpdateQuery;
type Path<Origin>;
type PrimaryKey;
type ManyField<Origin>;
type OneField<Origin>;
fn id() -> ModelId;
fn schema() -> app::Model;
fn register(model_set: &mut ModelSet);
fn new_path<Origin>(path: Path<Origin, Self>) -> Self::Path<Origin>;
fn new_root_path() -> Self::Path<Self> {
Self::new_path(Self::path_root())
}
fn path_root() -> Path<Self, Self> {
Path::from_model_id(Self::id())
}
fn path_field<U>(index: usize) -> Path<Self, U> {
Path::field_at(Self::id(), index)
}
fn path_model_list() -> Path<List<Self>, List<Self>> {
Path::from_model_id(Self::id())
}
fn new_create() -> Self::Create {
Self::Create::default()
}
fn new_many_field<Origin>(path: Path<Origin, List<Self>>) -> Self::ManyField<Origin>;
fn field_name_to_id(name: &str) -> FieldId;
fn find_by_primary_key(id: Expr<Self::PrimaryKey>) -> Self::Query<List<Self>>;
fn wrap_query<T>(stmt: crate::stmt::Query<T>) -> Self::Query<T>;
fn query_one(query: Self::Query<List<Self>>) -> Self::Query<Self>;
fn query_first(query: Self::Query<List<Self>>) -> Self::Query<Option<Self>>;
}
pub type QueryMany<M> = <M as Model>::Query<List<M>>;
pub type QueryOne<M> = <M as Model>::Query<M>;
pub type QueryOptionOne<M> = <M as Model>::Query<Option<M>>;