use async_trait::async_trait;
use log::info;

use crate::{
    modules::application::ApplicationFeature,
    topology::{K8sclient, Topology},
};

#[derive(Debug, Clone)]
pub struct PublicEndpoint {
    application_port: u16,
}

/// Use port 3000 as default port. Harmony wants to provide "sane defaults" in general, and in this
/// particular context, using port 80 goes against our philosophy to provide production grade
/// defaults out of the box. Using an unprivileged port is a good security practice and will allow
/// for unprivileged containers to work with this out of the box.
///
/// Now, why 3000 specifically? Many popular web/network frameworks use it by default, there is no
/// perfect answer for this but many Rust and Python libraries tend to use 3000.
impl Default for PublicEndpoint {
    fn default() -> Self {
        Self {
            application_port: 3000,
        }
    }
}

/// For now we only suport K8s ingress, but we will support more stuff at some point
#[async_trait]
impl<T: Topology + K8sclient + 'static> ApplicationFeature<T> for PublicEndpoint {
    async fn ensure_installed(&self, _topology: &T) -> Result<(), String> {
        info!(
            "Making sure public endpoint is installed for port {}",
            self.application_port
        );
        todo!()
    }
    fn name(&self) -> String {
        "PublicEndpoint".to_string()
    }
}
