using IWS5.Api.Enum;
using IWS5.Core.Services.IAdmin;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Swashbuckle.AspNetCore.Annotations;

namespace IWS5.AdminApi.Controllers;

[Authorize(Roles = nameof(UserGroups.PDAdminGroup))]
[Route("admin/schedules/task-types")]
[ApiController]
public class ScheduleTaskTypesController(
    IScheduleTasksService scheduleTasksService,
    ILogger<ScheduleTaskTypesController> logger)
    : ControllerBase
{
    /// <summary>
    /// Returns the list of schedule task types.
    /// </summary>
    [HttpGet]
    [SwaggerOperation(Summary = "Get all task types", Description = "Returns the list of schedule task types.")]
    public async Task<IActionResult> GetTaskTypes()
    {
        try
        {
            var types = await scheduleTasksService.GetTaskTypesAsync();
            return Ok(types);
        }
        catch (Exception ex)
        {
            logger.LogError(ex, "Failed to load task types");
            return StatusCode(500, new { success = false, message = "Failed to load task types" });
        }
    }

    /// <summary>
    /// Returns the list of schedule task action types.
    /// </summary>
    [HttpGet("actions")]
    [SwaggerOperation(Summary = "Get all task action types", Description = "Returns the list of schedule task action types.")]
    public async Task<IActionResult> GetTaskActionTypes()
    {
        try
        {
            var actions = await scheduleTasksService.GetTaskActionTypesAsync();
            return Ok(actions);
        }
        catch (Exception ex)
        {
            logger.LogError(ex, "Failed to load task action types");
            return StatusCode(500, new { success = false, message = "Failed to load task action types" });
        }
    }
}
