use crate::models::PaginatedResponse;

#[derive(Debug, Clone)]
pub struct PaginationHelper {
    pub page: i32,
    pub per_page: i32,
    pub offset: i64,
}

impl PaginationHelper {
    pub fn from_query(page: Option<i32>, per_page: Option<i32>) -> Self {
        let page = page.unwrap_or(1).max(1);
        let per_page = per_page.unwrap_or(25).min(100);
        let offset = ((page - 1) as i64) * (per_page as i64);
        
        Self { page, per_page, offset }
    }
    
    pub fn create_response<T>(&self, items: Vec<T>, total: i64) -> PaginatedResponse<T> {
        PaginatedResponse {
            items,
            total,
            page: self.page,
            per_page: self.per_page,
            has_more: (self.page as i64 * self.per_page as i64) < total,
        }
    }
}