using e_suite.Messaging.Common;
using eSuite.API.security;
using eSuite.API.Utilities;
using eSuite.Core.Miscellaneous;
using eSuite.Core.Security;
using Microsoft.AspNetCore.Mvc;

namespace eSuite.API.Controllers;

/// <summary>
/// Internal API used to trigger messages that the scheduler sends.
/// </summary>
[Route("api/[controller]")]
public class InternalMessagingController : ESuiteControllerBase
{
    private readonly ISigmaImportMessageSender _sigmaImportMessageSender;
    private readonly IDatabaseMessageSender _databaseMessageSender;
    private readonly IEFlowSyncMessageSender _eFlowSyncMessageSender;
    private readonly IActivityMessageSender _activityMessageSender;

    /// <summary>
    /// 
    /// </summary>
    /// <param name="sigmaImportMessageSender"></param>
    /// <param name="databaseMessageSender"></param>
    /// <param name="eFlowSyncMessageSender"></param>
    public InternalMessagingController(ISigmaImportMessageSender sigmaImportMessageSender, IDatabaseMessageSender databaseMessageSender, IEFlowSyncMessageSender eFlowSyncMessageSender, IActivityMessageSender activityMessageSender)
    {
        _sigmaImportMessageSender = sigmaImportMessageSender;
        _databaseMessageSender = databaseMessageSender;
        _eFlowSyncMessageSender = eFlowSyncMessageSender;
        _activityMessageSender = activityMessageSender;
    }

    /// <summary>
    /// 
    /// </summary>
    /// <returns></returns>
    [Route("PostImportGMGProfiles")]
    [HttpPost]
    [ProducesResponseType(StatusCodes.Status200OK)]
    [AccessKey(SecurityAccess.ImportGMGProfiles)]
#pragma warning disable IDE0060 // Remove unused parameter
    public Task PostImportGmgProfiles(CancellationToken cancellationToken)
#pragma warning restore IDE0060 // Remove unused parameter
    {
        _sigmaImportMessageSender.PostImportGMGProfiles();
        return Task.CompletedTask;
    }

    /// <summary>
    /// 
    /// </summary>
    /// <returns></returns>
    [Route("PostImportPrintSpecifications")]
    [HttpPost]
    [ProducesResponseType(StatusCodes.Status200OK)]
    [AccessKey(SecurityAccess.ImportPrintSpecifications)]
#pragma warning disable IDE0060 // Remove unused parameter
    public Task PostImportPrintSpecifications(CancellationToken cancellationToken)
#pragma warning restore IDE0060 // Remove unused parameter
    {
        _sigmaImportMessageSender.PostImportPrintSpecifications();
        return Task.CompletedTask;
    }

    /// <summary>
    /// 
    /// </summary>
    /// <returns></returns>
    [Route("PostClearOldEmailActions")]
    [HttpPost]
    [ProducesResponseType(StatusCodes.Status200OK)]
    [AccessKey(SecurityAccess.ClearOldEmailActions)]
#pragma warning disable IDE0060 // Remove unused parameter
    public Task PostClearOldEmailActions(CancellationToken cancellationToken)
#pragma warning restore IDE0060 // Remove unused parameter
    {
        _databaseMessageSender.PostClearOldEmailActions();
        return Task.CompletedTask;
    }

    /// <summary>
    /// 
    /// </summary>
    /// <returns></returns>
    [Route("PostClearOldPerformanceData")]
    [HttpPost]
    [ProducesResponseType(StatusCodes.Status200OK)]
    [AccessKey(SecurityAccess.ClearOldPerformanceData)]
#pragma warning disable IDE0060 // Remove unused parameter
    public Task PostClearOldPerformanceData(CancellationToken cancellationToken)
#pragma warning restore IDE0060 // Remove unused parameter
    {
        _databaseMessageSender.PostClearOldPerformanceData();
        return Task.CompletedTask;
    }

    /// <summary>
    /// 
    /// </summary>
    /// <returns></returns>
    [Route("PostClearOldSentinelData")]
    [HttpPost]
    [ProducesResponseType(StatusCodes.Status200OK)]
    [AccessKey(SecurityAccess.ClearOldSentinelData)]
#pragma warning disable IDE0060 // Remove unused parameter
    public Task PostClearOldSentinelData(CancellationToken cancellationToken)
#pragma warning restore IDE0060 // Remove unused parameter
    {
        _databaseMessageSender.PostClearOldSentinelData();
        return Task.CompletedTask;
    }

    /// <summary>
    /// 
    /// </summary>
    /// <returns></returns>
    [Route("PostClearOldSingleUserGuids")]
    [HttpPost]
    [ProducesResponseType(StatusCodes.Status200OK)]
    [AccessKey(SecurityAccess.ClearOldSingleUserGuids)]
#pragma warning disable IDE0060 // Remove unused parameter
    public Task PostClearOldSingleUserGuids(CancellationToken cancellationToken)
#pragma warning restore IDE0060 // Remove unused parameter
    {
        _databaseMessageSender.PostClearOldSingleUserGuids();
        return Task.CompletedTask;
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="cancellationToken"></param>
    /// <returns></returns>
    [Route("PostSyncEFlowPrinterCategories")]
    [HttpPost]
    [ProducesResponseType(StatusCodes.Status200OK)]
    [AccessKey(SecurityAccess.SyncEFlowPrinterCategories)]
#pragma warning disable IDE0060 // Remove unused parameter
    public Task SyncEFlowPrinterCategories(CancellationToken cancellationToken)
#pragma warning restore IDE0060 // Remove unused parameter
    {
        _eFlowSyncMessageSender.SyncEFlowPrinterCategories();
        return Task.CompletedTask;
    }

    /// <summary>
    /// This message is used to trigger progress on an activity. This is needed to make sure that activities that are waiting for a message to progress will continue to progress even if the message that should trigger the progress was not received (e.g. because the service was down when the message was sent).
    /// </summary>
    /// <param name="activityGeneralIdRef"></param>
    /// <param name="cancellationToken"></param>
    /// <returns></returns>
    [Route("ProgressActivity")]
    [HttpPost]
    [ProducesResponseType(StatusCodes.Status200OK)]
    [AccessKey(SecurityAccess.CreateActivity)]
#pragma warning disable IDE0060 // Remove unused parameter
    public Task ProgressActivity( [FromBody] GeneralIdRef activityGeneralIdRef, CancellationToken cancellationToken)
#pragma warning restore IDE0060 // Remove unused parameter
    {
        _activityMessageSender.ProgressActivity(activityGeneralIdRef);
        return Task.CompletedTask;
    }   
}