use async_trait::async_trait;
use dagger_cuddle_please::{models::CuddlePleaseSrcArgs, DaggerCuddlePlease};

use crate::{Context, MainAction};

#[derive(Clone)]
pub struct CuddlePlease {
    client: dagger_sdk::Query,
}

impl CuddlePlease {
    pub fn new(client: dagger_sdk::Query) -> Self {
        Self { client }
    }
}

#[async_trait]
impl MainAction for CuddlePlease {
    async fn execute_main(&self, _ctx: &mut Context) -> eyre::Result<()> {
        let client = self.client.clone();

        let action = DaggerCuddlePlease::new(client);

        action
            .cuddle_please_src(&CuddlePleaseSrcArgs {
                cuddle_image: "kasperhermansen/cuddle-please:main-1736464837".into(),
                server: dagger_cuddle_please::models::SrcServer::Gitea {
                    token: std::env::var("CUDDLE_PLEASE_TOKEN")
                        .expect("CUDDLE_PLEASE_TOKEN to be present"),
                },
                log_level: Some(dagger_cuddle_please::models::LogLevel::Debug),
            })
            .await?;

        Ok(())
    }
}
