use anyhow::Result;
use async_trait::async_trait;

use super::panel_adapter::{DiscoveredServer, FileEntry, PanelAdapter, ServerStatus};

/// AMP (Application Management Panel) adapter.
///
/// Communicates with AMP instances via their REST API to manage
/// Rust game servers. Implements the unified PanelAdapter trait
/// so the wipe engine and other services remain panel-agnostic.
pub struct AmpAdapter {
    pub api_endpoint: String,
    pub api_key: String,
}

impl AmpAdapter {
    pub fn new(api_endpoint: String, api_key: String) -> Self {
        Self {
            api_endpoint,
            api_key,
        }
    }
}

#[async_trait]
impl PanelAdapter for AmpAdapter {
    async fn test_connection(&self) -> Result<bool> {
        // TODO: POST to AMP API /API/Core/Login, verify session token returned
        todo!()
    }

    async fn discover_servers(&self) -> Result<Vec<DiscoveredServer>> {
        // TODO: GET instances from AMP API, map to DiscoveredServer
        todo!()
    }

    async fn get_server_status(&self, _server_id: &str) -> Result<ServerStatus> {
        // TODO: Query AMP instance status endpoint
        todo!()
    }

    async fn start_server(&self, _server_id: &str) -> Result<()> {
        // TODO: POST to AMP API /API/Core/Start
        todo!()
    }

    async fn stop_server(&self, _server_id: &str) -> Result<()> {
        // TODO: POST to AMP API /API/Core/Stop
        todo!()
    }

    async fn restart_server(&self, _server_id: &str) -> Result<()> {
        // TODO: POST to AMP API /API/Core/Restart
        todo!()
    }

    async fn send_command(&self, _server_id: &str, _command: &str) -> Result<String> {
        // TODO: POST to AMP API /API/Core/SendConsoleMessage
        todo!()
    }

    async fn get_file(&self, _server_id: &str, _path: &str) -> Result<Vec<u8>> {
        // TODO: GET file contents via AMP file manager API
        todo!()
    }

    async fn put_file(&self, _server_id: &str, _path: &str, _data: &[u8]) -> Result<()> {
        // TODO: Upload file via AMP file manager API
        todo!()
    }

    async fn delete_file(&self, _server_id: &str, _path: &str) -> Result<()> {
        // TODO: DELETE file via AMP file manager API
        todo!()
    }

    async fn list_files(&self, _server_id: &str, _path: &str) -> Result<Vec<FileEntry>> {
        // TODO: GET directory listing from AMP file manager API
        todo!()
    }

    async fn trigger_steam_update(&self, _server_id: &str) -> Result<()> {
        // TODO: POST to AMP API /API/Core/Update to trigger SteamCMD
        todo!()
    }
}
