using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using WK_KLI_LAPS_Service.App_Data;
using WK_KLI_LAPS_Service.Models.Configuration;
using WK_KLI_LAPS_Service.Models.Master;
using static WK_KLI_LAPS_Service.Controllers.Reports.ReportApiController;

namespace WK_KLI_LAPS_Service.Controllers.Configuration.Job.AutoArchiveJob
{
    [EnableCors("CorsPolicy")]
    [Authorize]
    [Route("api/[controller]")]
    [ApiController]
    public class AutoArchiveJobApiController : ControllerBase
{
        CommonRepository oCommonRepository = new CommonRepository();
        private IAutoArchiveJobService _AutoArchiveJobservices;
        public AutoArchiveJobApiController(IAutoArchiveJobService AutoArchiveJobServices)
        {
            _AutoArchiveJobservices = AutoArchiveJobServices;

        }


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

        [AllowAnonymous]
        [HttpPost("Edit_AutoArchiveJob")]
        public IActionResult Edit_AutoArchiveJob(autoarchivejobModel data)
        {
            try
            {
                var res = _AutoArchiveJobservices.Edit_AutoArchiveJob(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_AutoArchiveJob")]
        public IActionResult Active_AutoArchiveJob(autoarchivejobModel data)
        {
            try
            {
                var res = _AutoArchiveJobservices.Active_AutoArchiveJob(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_AutoArchiveJob")]
        public IActionResult Add_AutoArchiveJob(autoarchivejobModel data)
        {
            try
            {
                var res = _AutoArchiveJobservices.Add_AutoArchiveJob(data);

                return Ok();
            }
            catch (Exception ex)
            {
                oCommonRepository.ErrorLog(ex);
                // return error message if there was an exception
                return BadRequest(new { message = ex.Message });
            }
        }
        [Authorize]
        [HttpPost("GetJobTitle")]
        //Code to retrieve all data
        public IActionResult GetJobTitle([FromBody] manualarchivejobModel data)
        {
            var _list = _AutoArchiveJobservices.GetJobTitle(data);
            return Ok(_list);
        }
        [Authorize]
        [HttpPost("Jobarchieve")]
        //Code to retrieve all data
        public IActionResult Jobarchieve([FromBody] manualarchivejobModel data)
        {
            var _list = _AutoArchiveJobservices.Jobarchieve(data);
            return Ok(_list);
        }


    }
}
