//! Federation handlers — stubs returning Unimplemented.
//!
//! These will be wired to actual federation logic when the federation
//! subsystem is migrated to the v2 RPC framework.

use std::sync::Arc;

use bytes::Bytes;
use prost::Message;
use quicproquo_proto::qpq::v1;
use quicproquo_rpc::error::RpcStatus;
use quicproquo_rpc::method::{HandlerResult, RequestContext};

use super::ServerState;

fn unimplemented(name: &str) -> HandlerResult {
    HandlerResult::err(
        RpcStatus::Internal,
        &format!("{name}: federation not yet implemented in v2"),
    )
}

pub async fn handle_relay_enqueue(
    _state: Arc<ServerState>,
    _ctx: RequestContext,
) -> HandlerResult {
    unimplemented("RelayEnqueue")
}

pub async fn handle_relay_batch_enqueue(
    _state: Arc<ServerState>,
    _ctx: RequestContext,
) -> HandlerResult {
    unimplemented("RelayBatchEnqueue")
}

pub async fn handle_proxy_fetch_key_package(
    _state: Arc<ServerState>,
    _ctx: RequestContext,
) -> HandlerResult {
    unimplemented("ProxyFetchKeyPackage")
}

pub async fn handle_proxy_fetch_hybrid_key(
    _state: Arc<ServerState>,
    _ctx: RequestContext,
) -> HandlerResult {
    unimplemented("ProxyFetchHybridKey")
}

pub async fn handle_proxy_resolve_user(
    _state: Arc<ServerState>,
    _ctx: RequestContext,
) -> HandlerResult {
    unimplemented("ProxyResolveUser")
}

pub async fn handle_federation_health(
    _state: Arc<ServerState>,
    _ctx: RequestContext,
) -> HandlerResult {
    let proto = v1::FederationHealthResponse {
        status: "ok".into(),
        server_domain: String::new(),
    };
    HandlerResult::ok(Bytes::from(proto.encode_to_vec()))
}
