using ScadaLink.Commons.Messages.InboundApi;
using ScadaLink.Communication;

namespace ScadaLink.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;

    public CommunicationServiceInstanceRouter(CommunicationService communicationService)
    {
        _communicationService = communicationService;
    }

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

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

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