use async_trait::async_trait;
use anyhow::Result;
use uuid::Uuid;
use crate::domain::entity::{Booth, EventBoothState};
#[derive(Debug, Clone, Default)]
pub struct BoothPaginationParams {
pub page: u32,
pub per_page: u32,
}
impl BoothPaginationParams {
pub fn new(page: u32, per_page: u32) -> Self {
Self { page, per_page }
}
pub fn offset(&self) -> u64 {
((self.page.saturating_sub(1)) * self.per_page) as u64
}
pub fn limit(&self) -> u64 {
self.per_page as u64
}
}
#[derive(Debug, Clone)]
pub struct BoothPaginatedResult {
pub data: Vec<Booth>,
pub total: u64,
pub page: u32,
pub per_page: u32,
}
#[derive(Debug, Clone, Default)]
pub struct BoothFilter {
pub event_id: Option<Uuid>,
pub booth_category_id: Option<Uuid>,
pub name: Option<String>,
pub state: Option<EventBoothState>,
pub partner_id: Option<Uuid>,
pub contact_name: Option<String>,
pub contact_email: Option<String>,
pub contact_phone: Option<String>,
pub sale_order_line_id: Option<Uuid>,
pub is_paid: Option<bool>,
}
impl BoothFilter {
pub fn has_filters(&self) -> bool {
self.event_id.is_some() || self.booth_category_id.is_some() || self.name.is_some() || self.state.is_some() || self.partner_id.is_some() || self.contact_name.is_some() || self.contact_email.is_some() || self.contact_phone.is_some() || self.sale_order_line_id.is_some() || self.is_paid.is_some()
}
}
#[async_trait]
pub trait BoothRepository: Send + Sync {
async fn save(&self, entity: &Booth) -> Result<Booth>;
async fn find_by_id(&self, id: &str) -> Result<Option<Booth>>;
async fn find_all(&self) -> Result<Vec<Booth>>;
async fn update(&self, id: &str, entity: &Booth) -> Result<Option<Booth>>;
async fn delete(&self, id: &str) -> Result<bool>;
async fn list(&self, params: BoothPaginationParams) -> Result<BoothPaginatedResult>;
async fn list_with_filters(&self, params: BoothPaginationParams, filters: BoothFilter) -> Result<BoothPaginatedResult>;
async fn count(&self) -> Result<u64>;
async fn count_with_filters(&self, filters: BoothFilter) -> Result<u64>;
async fn exists(&self, id: &str) -> Result<bool>;
async fn soft_delete(&self, id: &str) -> Result<bool>;
async fn restore(&self, id: &str) -> Result<Option<Booth>>;
async fn list_deleted(&self, params: BoothPaginationParams) -> Result<BoothPaginatedResult>;
async fn empty_trash(&self) -> Result<u64>;
async fn bulk_save(&self, entities: &[Booth]) -> Result<Vec<Booth>>;
async fn bulk_delete(&self, ids: &[&str]) -> Result<u64>;
}