// Copyright (C) 2023  Aravinth Manivannan <realaravinth@batsense.net>
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
//
// SPDX-License-Identifier: AGPL-3.0-or-later

use actix_web::web::ServiceConfig;

pub mod db;
pub mod hooks;

pub fn services(cfg: &mut ServiceConfig) {
    hooks::services(cfg);
}

pub mod routes {
    use serde::{Deserialize, Serialize};

    #[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
    pub struct Mcaptcha {
        pub upload: &'static str,
        pub download: &'static str,
        pub register: &'static str,
    }

    impl Mcaptcha {
        pub const fn new() -> Self {
            Self {
                register: "/mcaptcha/api/v1/register",
                upload: "/mcaptcha/api/v1/{campaign_id}/upload",
                download: "/mcapthca/api/v1/{campaign_id}/download",
            }
        }

        pub fn get_download_route(&self, campaign_id: &str, page: usize) -> String {
            format!(
                "{}?page={}",
                self.download.replace("{campaign_id}", campaign_id),
                page
            )
        }

        pub fn get_upload_route(&self, campaign_id: &str) -> String {
            self.upload.replace("{campaign_id}", campaign_id)
        }
    }
}
