using adas_core.Application.Services.Interfaces;
using adas_core.Authentication.Attributes;
using adas_core.Domain.Enums;
using adas_core.Domain.Models;
using adas_core.Domain.Models.DTO;
using adas_core.Logging;
using Microsoft.AspNetCore.Mvc;

namespace adas_core.Controllers;

[Route("alerts")]
[ApiController]
public class RecordingAlertController : ControllerBase
{
    private readonly IRecordingAlertService _recordingAlertService;


    public RecordingAlertController(IRecordingAlertService recordingAlertService)
    {
        LogExecutionContext.TrySetTraceIdentifier(Guid.NewGuid().ToString(), true);

        _recordingAlertService = recordingAlertService;
    }


    [HttpPost]
    [Route("")]
    [AuthorizeRoles(PermissionEnum.RolesType.AuthSome)]
    [PermissionAuthorize("Source", "DisplayId")]
    public IActionResult ProcessRequest([FromBody] RecordingAlertDto recordingAlertDto)
    {
        var request = new ApiRequest
        {
            TraceId = Guid.NewGuid().ToString(),
            Type = "RecordingAlert",
            PatientNumber = recordingAlertDto.PatientNumber,
            Location = recordingAlertDto.Location,
            RecordingAlerts = recordingAlertDto.RecordingAlerts,
            Recording = recordingAlertDto.RecordingData,
            MessageTime = recordingAlertDto.MessageTime,
            WaitResult = recordingAlertDto.WaitResult
        };

        if (request.WaitResult) _recordingAlertService.SaveRequest(request);
        else _recordingAlertService.SaveRequestAsync(request);

        return Ok();
    }
}