using BPM_Service.Models.Master;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Mvc;
using System;
using WK_KLI_LAPS_Service.App_Data;
using WK_KLI_LAPS_Service.Models.Master;

namespace WK_KLI_LAPS_Service.Controllers.Master.PrintSupplement
{
    [EnableCors("CorsPolicy")]
    [Authorize]
    [Route("api/[controller]")]
    [ApiController]
    public class PrintSupplementApiController : ControllerBase
    {
        CommonRepository oCommonRepository = new CommonRepository();

        private IPrintSupplementService _PrintSupplementservices;

        public PrintSupplementApiController(IPrintSupplementService PrintSupplementServices)
        {
            _PrintSupplementservices = PrintSupplementServices;

        }

        [Authorize]
        [HttpGet]
        //Code to retrieve all data
        public IActionResult GetAll()
        {
            var _list = _PrintSupplementservices.GetAll();
            return Ok(_list);
        }

        [Authorize]
        [HttpGet("GetActivePrintSupplement")]
        //Code to retrieve active data
        public IActionResult GetActivePrintSupplement()
        {
            var _list = _PrintSupplementservices.GetActivePrintSupplement();
            return Ok(_list);
        }
        //Code to add new record
        [Authorize]
        [HttpPost("Add")]
        public IActionResult Add([FromBody] printsupplementModel oprintsupplementModel)
        {

            int retval = 0;
            try
            {
                retval = _PrintSupplementservices.Add(oprintsupplementModel);
                return Ok(retval);
            }
            catch (Exception ex)
            {
                oCommonRepository.ErrorLog(ex);
                // return error message if there was an exception
                return BadRequest(new { message = ex.Message });
            }

        }
        //Code to update specific record
        [Authorize]
        [HttpPost("Update")]
        public IActionResult Update([FromBody] printsupplementModel oprintsupplementModel)
        {
            int retval = 0;
            try
            {
                retval = _PrintSupplementservices.Edit(oprintsupplementModel);
                return Ok(retval);
            }
            catch (Exception ex)
            {
                oCommonRepository.ErrorLog(ex);
                // return error message if there was an exception
                return BadRequest(new { message = ex.Message });
            }
        }


        //Code to activate or deactivate specific record
        [Authorize]
        [HttpPost("activeordeactive")]
        public IActionResult Delete([FromBody] printsupplementModel oprintsupplementModel)
        {
            int retval = 0;
            try
            {
                retval = _PrintSupplementservices.Delete(oprintsupplementModel);
                return Ok(retval);
            }
            catch (Exception ex)
            {
                oCommonRepository.ErrorLog(ex);
                // return error message if there was an exception
                return BadRequest(new { message = ex.Message });
            }
        }

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

    }
}