using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Mvc;
using System;
using WK_KLI_LAPS_Service.App_Data;
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.Models.Master;



namespace WK_KLI_LAPS_Service.Controllers.Master.Chartvalue
{
    [EnableCors("CorsPolicy")]
    [Authorize]
    [Route("api/[controller]")]
    [ApiController]
    public class ChartValuesApiController : ControllerBase
    {
        CommonRepository oCommonRepository = new CommonRepository();
        private IChartValuesService _ChartValuesservices;
        public ChartValuesApiController(IChartValuesService ChartValuesServices)
        {
            _ChartValuesservices = ChartValuesServices;

        }

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

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

        [AllowAnonymous]
        [HttpPost("Active_ChartValues")]
        public IActionResult Active_ChartValues(chartvalueModel data)
        {
            try
            {
                var res = _ChartValuesservices.Active_ChartValues(data);

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

        [AllowAnonymous]
        [HttpPost("Add_ChartValues")]
        public IActionResult Add_ChartValues(chartvalueModel data)
        {
            try
            {
                var res = _ChartValuesservices.Add_ChartValues(data);

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

        [AllowAnonymous]
        [HttpPost("Edit_ChartValues")]
        public IActionResult Edit_Error(chartvalueModel data)
        {
            try
            {
                var res = _ChartValuesservices.Edit_ChartValues(data);

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

    }

}

