using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using System;
using WK_KLI_LAPS_Service.App_Data;
using WK_KLI_LAPS_Service.Controllers.Master.Error;
using WK_KLI_LAPS_Service.Models.Master;

namespace WK_KLI_LAPS_Service.Controllers.Master.Lob
{
    [Route("api/[controller]")]
[ApiController]
public class LobApiController : ControllerBase
{

        CommonRepository oCommonRepository = new CommonRepository();
        private ILobService _Lobservices;
        public LobApiController(ILobService LobServices)
        {
            _Lobservices = LobServices;

        }

        [AllowAnonymous]
        [HttpGet("Getall")]
        public IActionResult Getall()
        {
            try
            {
                var list = _Lobservices.GetAll();

                return Ok(list);
            }
            catch (Exception ex)
            {
                oCommonRepository.ErrorLog(ex);
                // return error message if there was an exception
                return BadRequest(new { message = ex.Message });
            }
        }

        [Authorize]
        [HttpGet("GetActiveLob")]
        //Code to retrieve active data
        public IActionResult GetActiveLob()
        {
            var _list = _Lobservices.GetActiveLob();
            return Ok(_list);
        }

        [AllowAnonymous]
        [HttpPost("Edit_Lob")]
        public IActionResult Edit_Lob(lobModel data)
        {
            try
            {
                var res = _Lobservices.Edit_Lob(data);

                return Ok();
            }
            catch (Exception ex)
            {
                oCommonRepository.ErrorLog(ex);
                // return error message if there was an exception
                return BadRequest(new { message = ex.Message });
            }
        }

        [AllowAnonymous]
        [HttpPost("Active_Lob")]
        public IActionResult Active_Lob(lobModel data)
        {
            try
            {
                var res = _Lobservices.Active_Lob(data);

                return Ok();
            }
            catch (Exception ex)
            {
                oCommonRepository.ErrorLog(ex);
                // return error message if there was an exception
                return BadRequest(new { message = ex.Message });
            }
        }

        [AllowAnonymous]
        [HttpPost("Add_Lob")]
        public IActionResult Add_Lob(lobModel data)
        {
            try
            {
                var res = _Lobservices.Add_Lob(data);

                return Ok();
            }
            catch (Exception ex)
            {
                oCommonRepository.ErrorLog(ex);
                // return error message if there was an exception
                return BadRequest(new { message = ex.Message });
            }
        }
       
        [AllowAnonymous]
        [HttpGet("Get_Loblst")]
        public IActionResult Get_Errorlst()
        {
            try
            {
                var res = _Lobservices.Get_Loblst();

                return Ok(res);
            }
            catch (Exception ex)
            {
                oCommonRepository.ErrorLog(ex);
                // return error message if there was an exception
                return BadRequest(new { message = ex.Message });
            }
        }
    }
}
