use std::fmt::Debug;
use tokio_postgres::Row;

use super::EntityId;
use super::EntityMetadata;
use crate::query::NonNullTableAlias;
use crate::query::QueryBindings;

pub trait Entity: Debug + Clone + Sync + EntityMetadata {
    const ID_COLUMN_INDEX: usize;

    type EntityIdType: Entity;
    fn id(&self) -> &EntityId<Self::EntityIdType>;

    fn from_db_row(row: &Row, offset: usize) -> Self;
    fn bind_db_params<'a>(&'a self, bindings: &mut QueryBindings<'a>);

    fn alias(alias: &'static str) -> NonNullTableAlias<Self> {
        return NonNullTableAlias::new(alias);
    }
}

pub trait VersionedEntity: Entity {
    const VERSION_COLUMN_INDEX: usize;
    fn version(&self) -> i32;
}
