using IWS5.Core.Enums;
using IWS5.Core.Models;
using Microsoft.AspNetCore.Mvc;

namespace IWS5.Api.Helpers;

internal static class ResponseMapper<T> where T : class
{
    internal static IActionResult MapServiceResponse(CodeResponse<T> response)
    {
        return response.Code switch
        {
            ResponseCode.OK => new OkObjectResult(response.ResponseModel),
            ResponseCode.Unauthorized => new UnauthorizedObjectResult(new {error = response.Message}),
            ResponseCode.NotFound => new NotFoundObjectResult(new {error = response.Message}),
            ResponseCode.BadRequest => new BadRequestObjectResult(new {error = response.Message}),
            ResponseCode.Conflict => new ConflictObjectResult(new {error = response.Message}),
            _ => new ObjectResult(new {error = response.Message}) { StatusCode = 500 }
        };
    }
}