use chrono::NaiveDateTime;
use petro::entity::SubentityList;
use rust_decimal::Decimal;

use petro::entity::Entity;
use petro::entity::EntityId;
use petro::entity::EntityRef;

use super::Customer;

#[derive(Entity, Debug, Clone)]
#[petro(table = "sales_order", id = "id")]
pub struct Order {
    pub id: EntityId<Order>,
    pub order_number: String,
    pub order_date: Option<NaiveDateTime>,
    pub customer: EntityRef<Customer>,
    pub total_amount: Decimal,
    pub line_items: SubentityList<LineItem>,
}

#[derive(Entity, Debug, Clone)]
#[petro(table = "line_item", id = "id")]
pub struct LineItem {
    pub id: EntityId<LineItem>,
    pub order: EntityRef<Order>,
    pub description: String,
    pub line_total: Decimal,
}
