use crate::executors::ExecutorError;
use async_trait::async_trait;

use super::{IpAddress, Url};

#[async_trait]
pub trait TftpServer: Send + Sync {
    async fn serve_files(&self, url: &Url) -> Result<(), ExecutorError>;
    fn get_ip(&self) -> IpAddress;

    async fn set_ip(&self, ip: IpAddress) -> Result<(), ExecutorError>;
    async fn ensure_initialized(&self) -> Result<(), ExecutorError>;
    async fn commit_config(&self) -> Result<(), ExecutorError>;
    async fn reload_restart(&self) -> Result<(), ExecutorError>;
}

impl std::fmt::Debug for dyn TftpServer {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.write_fmt(format_args!(
            "TftpServer serving files at {}",
            self.get_ip()
        ))
    }
}
