using Application.Endpoints;
using Application.Endpoints.Chats;
using Application.Services.Database;
using Application.Services.Database.MongoDB;
using Microsoft.AspNetCore.Mvc;

namespace API.Controllers;

public class ChatController : BaseApiController
{
    private readonly IChatMongoDbService _chatMongoDbService;
    private readonly IPatientRepository _patientRepository;
    private readonly IDoctorRepository _doctorRepository;

    public ChatController(IChatMongoDbService chatMongoDbService, IPatientRepository patientRepository,
        IDoctorRepository doctorRepository)
    {
        _chatMongoDbService = chatMongoDbService;
        _patientRepository = patientRepository;
        _doctorRepository = doctorRepository;
    }
    
    [HttpPost("send_message")]
    public async Task<ActionResult<BaseResponse>> SendMessage(SendMessageDto sendMessageDto)
    {
        var handler = new ChatHandler(_chatMongoDbService, _patientRepository, _doctorRepository);
        var response = await handler.HandleSendMessage(sendMessageDto).ConfigureAwait(false);
        return StatusCode(response.StatusCode, response);
    }
    
    [HttpPost("get_conversation")]
    public async Task<ActionResult<BaseResponse>> GetConversation(GetConversationDto getConversationDto)
    {
        var handler = new ChatHandler(_chatMongoDbService, _patientRepository, _doctorRepository);
        var response = await handler.HandleGetConversation(getConversationDto).ConfigureAwait(false);
        return StatusCode(response.StatusCode, response);
    }
}