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.Controllers.Master.Lob;
using WK_KLI_LAPS_Service.Models.Master;

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

    // GET api/<LobDetailsApiController>/5
    [HttpGet("{id}")]
    public string Get(int id)
    {
        return "value";
    }
        CommonRepository oCommonRepository = new CommonRepository();
        private ILobDetailsService _LobDetailsservices;
        public LobDetailsApiController(ILobDetailsService LobDetailsServices)
        {
            _LobDetailsservices = LobDetailsServices;

        }

        [AllowAnonymous]
        [HttpGet("Getall")]
        public IActionResult Getall()
        {
            try
            {
                var list = _LobDetailsservices.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("GetActiveLobDetails")]
        //Code to retrieve active data
        public IActionResult GetActiveLobDetails()
        {
            var _list = _LobDetailsservices.GetActiveLobDetails();
            return Ok(_list);
        }

        [AllowAnonymous]
        [HttpPost("Edit_LobDetails")]
        public IActionResult Edit_LobDetails(LobDetailesModel data)
        {
            try
            {
                var res = _LobDetailsservices.Edit_LobDetails(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_LobDetails")]
        public IActionResult Active_LobDetails(LobDetailesModel data)
        {
            try
            {
                var res = _LobDetailsservices.Active_LobDetails(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_LobDetails")]
        public IActionResult Add_LobDetails(LobDetailesModel data)
        {
            try
            {
                var res = _LobDetailsservices.Add_LobDetails(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("Get_LobDetailslst")]
        public IActionResult Get_LobDetailslst(LobDetailesModel data)
        {
            try
            {
                var res = _LobDetailsservices.Get_LobDetailslst(data);

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