1use crate::{
2 db::UserId,
3 llm::db::{BillingEventId, ModelId},
4};
5use sea_orm::entity::prelude::*;
6
7#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
8#[sea_orm(table_name = "billing_events")]
9pub struct Model {
10 #[sea_orm(primary_key)]
11 pub id: BillingEventId,
12 pub idempotency_key: Uuid,
13 pub user_id: UserId,
14 pub model_id: ModelId,
15 pub input_tokens: i64,
16 pub input_cache_creation_tokens: i64,
17 pub input_cache_read_tokens: i64,
18 pub output_tokens: i64,
19}
20
21#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
22pub enum Relation {
23 #[sea_orm(
24 belongs_to = "super::model::Entity",
25 from = "Column::ModelId",
26 to = "super::model::Column::Id"
27 )]
28 Model,
29}
30
31impl Related<super::model::Entity> for Entity {
32 fn to() -> RelationDef {
33 Relation::Model.def()
34 }
35}
36
37impl ActiveModelBehavior for ActiveModel {}