using Microsoft.AspNetCore.Mvc;
using Serilog;
using WorkFlowCheck.BL.Services;
using WorkFlowCheck.BL.Services.Interfaces;
using WorkFlowCheck.Common.DTO;

namespace WorkFlowCheck.API.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class CheckListController : ControllerBase
    {
        private ICheckListService _checkListService;
        public CheckListController(ICheckListService checkListService)
        {
            _checkListService = checkListService;
        }
        
        [HttpGet("GetCheckListHeader/{id}")]
        public async Task<ApiResponseDTO<CheckListHeaderDTO>> GetCheckListHeader(int id)
        {
            var retVal = new ApiResponseDTO<CheckListHeaderDTO>()
            {
                IsSuccess = true,
            };
            var checkListHeaderDTO = await _checkListService.GetCheckListHeaderAsync(id );

            if (checkListHeaderDTO != null)
            {
                
                    retVal.IsSuccess = true;
                    retVal.Data = checkListHeaderDTO;
            }
            else
            {
                retVal.IsSuccess = false;
                retVal.Errors.Add("No data!");
            }

            return retVal;
        }

        [HttpPost("StartNew")]
        public async Task<ApiResponseDTO<CheckListHeaderDTO>> StartNew([FromBody] ApiRequestDTO<CheckListTemplateHeaderDTO> request)
        {
            var retVal = new ApiResponseDTO<CheckListHeaderDTO>()
            {
                IsSuccess = true
            };

            try
            {
                var response = await _checkListService.StartNewCheckListAsync(request);
            }
            catch (Exception ex)
            {

                Log.Error(ex.Message);
            }
            return retVal;
        }
    }
}
