using ZB.MOM.WW.ScadaBridge.Commons.Messages.InboundApi;
using ZB.MOM.WW.ScadaBridge.Communication;

namespace ZB.MOM.WW.ScadaBridge.InboundAPI;

/// <summary>
/// Default <see cref="IInstanceRouter"/> implementation. Delegates every routed
/// call to <see cref="CommunicationService"/>, which dispatches to the target
/// site cluster via the central communication actor.
/// </summary>
public sealed class CommunicationServiceInstanceRouter : IInstanceRouter
{
    private readonly CommunicationService _communicationService;

    /// <summary>
    /// Initializes the router with the central communication service.
    /// </summary>
    /// <param name="communicationService">Service used to dispatch routed calls to site clusters.</param>
    public CommunicationServiceInstanceRouter(CommunicationService communicationService)
    {
        _communicationService = communicationService;
    }

    /// <inheritdoc />
    public Task<RouteToCallResponse> RouteToCallAsync(
        string siteId, RouteToCallRequest request, CancellationToken cancellationToken) =>
        _communicationService.RouteToCallAsync(siteId, request, cancellationToken);

    /// <inheritdoc />
    public Task<RouteToGetAttributesResponse> RouteToGetAttributesAsync(
        string siteId, RouteToGetAttributesRequest request, CancellationToken cancellationToken) =>
        _communicationService.RouteToGetAttributesAsync(siteId, request, cancellationToken);

    /// <inheritdoc />
    public Task<RouteToSetAttributesResponse> RouteToSetAttributesAsync(
        string siteId, RouteToSetAttributesRequest request, CancellationToken cancellationToken) =>
        _communicationService.RouteToSetAttributesAsync(siteId, request, cancellationToken);

    /// <inheritdoc />
    public Task<RouteToWaitForAttributeResponse> RouteToWaitForAttributeAsync(
        string siteId, RouteToWaitForAttributeRequest request, CancellationToken cancellationToken) =>
        _communicationService.RouteToWaitForAttributeAsync(siteId, request, cancellationToken);
}
