using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using WK_KLI_LAPS_Service.App_Data;
using WK_KLI_LAPS_Service.Models.Configuration;

namespace WK_KLI_LAPS_Service.Controllers.Configuration.Outline.OutlineStageMapping
{
    [Route("api/[controller]")]
    [ApiController]
    public class OutlineStageMappingApiController : ControllerBase
    {
        CommonRepository oCommonRepository = new CommonRepository();

        private IOutlineStageMappingService _IOutlineStageMappingApiController;
        public OutlineStageMappingApiController(IOutlineStageMappingService outlineStageMappingApiController)
        {
            _IOutlineStageMappingApiController = outlineStageMappingApiController;
        }

        [Authorize]
        [HttpPost("UpdateOutlineStageMapping")]
        public IActionResult UpdateOutlineStageMapping([FromBody] List<outlineStageMappingModel> ooutlineStageMappingModel)
        {
            try
            {
                string inputstr = JsonConvert.SerializeObject(ooutlineStageMappingModel);
                var _mappedWorkFlowDefinition = _IOutlineStageMappingApiController.UpdateOutlineStageMapping(inputstr, "insert");
                return Ok(_mappedWorkFlowDefinition);
            }
            catch (Exception ex)
            {
                oCommonRepository.ErrorLog(ex);
                // return error message if there was an exception
                return BadRequest(new { message = ex.Message });
            }
        }

        [Authorize]
        [HttpPost("Getbyoutlineconfigid")]
        //Code to retrieve all data
        public IActionResult Getbyoutlineconfigid([FromBody] outlineStageMappingModel ooutlineStageMappingModel)
        {
            var _mappedWorkFlowDefinition = _IOutlineStageMappingApiController.Getbyoutlineconfigid(ooutlineStageMappingModel, "getbyoutlineconfigid");
            return Ok(_mappedWorkFlowDefinition);
        }
    }
}