use rust_decimal::Decimal;
use sqlx::Row;
use uuid::Uuid;
use crate::infrastructure::persistence::PosDiscountRepository;
pub struct DiscountRow {
pub id: Uuid,
pub name: String,
pub percentage: Decimal,
}
impl PosDiscountRepository {
pub async fn fetch_discount(
&self,
conn: &mut sqlx::PgConnection,
discount_id: Uuid,
) -> Result<Option<DiscountRow>, sqlx::Error> {
let row = sqlx::query(
r#"SELECT id, name, percentage
FROM pos.pos_discounts
WHERE id=$1 AND (metadata->>'deleted_at') IS NULL"#,
)
.bind(discount_id)
.fetch_optional(conn)
.await?;
Ok(row.map(|r| DiscountRow {
id: r.get("id"),
name: r.get("name"),
percentage: r.get("percentage"),
}))
}
}