using LHDN.CRM.BC.Services;
using LHDN.CRM.Models.Models.CallingCenter;
using LHDN.CRM.WebAPI.Filters;
using Swashbuckle.Swagger.Annotations;
using System;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;

namespace LHDN.CRM.WebAPI.Controllers.Api
{
    [ApiErrorHandler]
    [EnableSwagger]
    [RoutePrefix("api/CallingCentre")]
    public class CallingCentreController : ApiController
    {

        /// <summary>
        /// [Digital] Verification before CC routing
        /// </summary>
        /// <remarks>
        /// CC Backend Verification before Workplace Desktop (WD)
        /// </remarks>
        /// <param name="request">VerifyRequest Model</param>
        [SwaggerResponse(HttpStatusCode.OK, Type = typeof(VerifyResponse))]
        [HttpGet]
        [Route("TaxPayer/Verify")]
        public HttpResponseMessage Verify([FromUri] VerifyRequest request)
        {
            return Request.CreateResponse(HttpStatusCode.OK,
                    new VerifyResponse
                    {
                        Authenticated = true,
                        Name = "MOHD ZAWAWI BIN OMAR",
                        IDNo = "840802136017",
                        IDType = 1,
                        FacebookID = "e123u789212312",
                        TwitterID = "",
                        Email = "btheng9642@yahoo.com",
                        PhoneNo = "0121234567",
                        TaxNo = "SG 25248315040",
                        TaxAgent = false
                    });
        }

        /// <summary>
        /// [Voice] CC Request Language Preference from CRM
        /// </summary>
        /// <remarks>
        /// CC Backend Verification before Workplace Desktop (WD) <br />
        /// <br />
        /// To test Duplicate records: PhoneNo: 0128888881 <br />
        /// To test No record Found: PhoneNo: 0128888882 <br />
        /// <br />        
        /// LanguageID: <br />
        /// 0	No Language Preference <br />
        /// 1	Bahasa Malaysia <br />
        /// 2	Bahasa Inggeris <br />
        /// </remarks>
        [SwaggerResponse(HttpStatusCode.OK, Type = typeof(LanguageResponse))]
        [HttpGet]
        [Route("TaxPayer/Language")]
        public HttpResponseMessage Language([FromUri] LanguageRequest request)
        {
            if (request.PhoneNo == "0128888881")
            {
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Duplicate records Found"));
            }
            else if (request.PhoneNo == "0128888882")
            {
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "No record Found"));
            }
            else
            {

                return Request.CreateResponse(HttpStatusCode.OK,
                    new LanguageResponse
                    {                       
                        LanguageID = 1
                    });
            }
        }

        /// <summary>
        /// [Voice] CC to check Blacklist and Travel Restriction status from CRM
        /// </summary>
        [SwaggerResponse(HttpStatusCode.OK, Type = typeof(BlacklistResponse))]
        [HttpGet]
        [Route("TaxPayer/BlacklistSekatan")]
        public HttpResponseMessage Blacklist([FromUri] BlacklistRequest request)
        {
            return Request.CreateResponse(HttpStatusCode.OK,
                new BlacklistResponse
                {
                    VIP = false,
                    S22 = false,
                    S75A = false,
                    S104 = true,
                    DebitList = false
                });
        }

        /// <summary>
        /// [Voice] Self Service Option Verification using NRIC only or multiple parameter
        /// </summary>
        [SwaggerResponse(HttpStatusCode.OK, Type = typeof(ServiceVerificationResponse))]
        [HttpGet]
        [Route("SelfServices/Verify")]
        public HttpResponseMessage SelfserviceVerification([FromUri] ServiceVerificationRequest request)
        {
            return Request.CreateResponse(HttpStatusCode.OK,
                new ServiceVerificationResponse
                {
                    IDNo = "840802136017",
                    IDType = 1,
                    InteractionID = "",
                    Channel = 0,
                    SocialName = "",
                    DOB = Convert.ToDateTime("1988/11/30"),
                    PostCode = "53300",
                    AccountNo = "0134",
                    PhoneNo = "0121234567",
                });
        }

        /// <summary>
        /// [Voice] CC to query CRM for Hotline verification
        /// </summary>
        [SwaggerResponse(HttpStatusCode.OK, Type = typeof(HotlineResponse))]
        [HttpGet]
        [Route("Voice/Hotline")]
        public HttpResponseMessage VoiceHotlineVerification([FromBody]  HotlineRequest request)
        {
            return Request.CreateResponse(HttpStatusCode.OK,
                new HotlineResponse
                {
                    IDNo = "840802136017",
                    IDType = 1,
                    Name = "MOHD ZAWAWI BIN OMAR",
                    PhoneNo = "0121234567",
                    TaxFileNumber = "SG 25248315040",
                    LanguageID = 1,
                    CaseID = 0,
                    TaxFileLocation = "WANGSA MAJU"
                });
        }


        /// <summary>
        /// [Voice] CC update Language Preference to CRM
        /// </summary>
        [SwaggerResponse(HttpStatusCode.OK)]
        [HttpPost]
        [Route("TaxPayer/UpdateLanguage")]
        public HttpResponseMessage UpdateLanguage([FromUri] UpdateLanguageRequest request)
        {
            return Request.CreateResponse(HttpStatusCode.OK);
        }


    }
}
