use loco_rs::prelude::*;

use crate::services::subscriptions;

pub struct SendMonthlyDigest;

#[async_trait]
impl Task for SendMonthlyDigest {
    fn task(&self) -> TaskInfo {
        TaskInfo {
            name: "send_monthly_digest".to_string(),
            detail: "queue monthly digest notifications".to_string(),
        }
    }

    async fn run(&self, app_context: &AppContext, _vars: &task::Vars) -> Result<()> {
        let summary = subscriptions::send_digest(app_context, "monthly").await?;
        tracing::info!(
            "send_monthly_digest queued={} skipped={} posts={}",
            summary.queued,
            summary.skipped,
            summary.post_count
        );
        Ok(())
    }
}
