using BPMService.Models;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using WK_KLI_LAPS_Service.Models;

// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860

namespace WK_KLI_LAPS_Service.Controllers.Common.SendMail
{
    [EnableCors("CorsPolicy")]
    [Authorize]
    [ApiController]
    [Route("api/[controller]")]
    public class SendMailApiController : ControllerBase
    {
        private ISendMailService _sendmailService;
        private readonly Appsettings _appSettings;

        public SendMailApiController(ISendMailService sendmailService, IOptions<Appsettings> appSettings)
        {
            _sendmailService = sendmailService;
            _appSettings = appSettings.Value;
        }

        [AllowAnonymous]
        [HttpPost("SendEmail/{emailid}/{type}")]
        public IActionResult SendEmail(string emailid, string type)
        {
            var res = false;
            if (type != "useradd" && type != "accessrequest")
            {
                res = _sendmailService.FindbyMailId_user(emailid);
            }
            if (res == false)
            {
                string status = _sendmailService.sendmail(emailid, type, _appSettings);
                if (status.ToString().Equals("success"))
                    return Ok();
                else
                    return BadRequest(status);
            }
            else
            {
                return BadRequest("Email Id not exists");
            }
        }
        [AllowAnonymous]
        [HttpPost("SendVendorEmail")]
        public IActionResult SendVendorEmail([FromBody] vendoremail data)
        {
            //var dt = oUploaderService.getlotstatusbytrankey(L.ToString().Trim());
            //if (dt == null)
            //{
            //    return BadRequest(new { message = "Link is not valid" });
            //}
            //var i1_dt = JsonConvert.DeserializeObject<object>(dt.ToString());
            //JArray a1_dt = JArray.Parse(i1_dt.ToString());
            //JObject obj1_dt = JObject.Parse(a1_dt[0].ToString());
            //if (obj1_dt["lotstatus"].ToString() == "C")
            //{
            //    return BadRequest(new { message = "Job is already completed" });
            //}


            return Ok("done");
        }



    }
}
