using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using MS.Services;
using MS.Services.PosTrxService;
using MS.WebCore.Core;
using MS.WebCore.Dto;
using System;
using System.Threading.Tasks;

namespace MS.WebApi.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class TransactionStatusController : ControllerBase
    {
        private readonly IPosTrxService _PosTrxService;
        public TransactionStatusController(IPosTrxService posTrxService)
        {
            _PosTrxService = posTrxService;
        }
        [Route("GetTransactionStatus")]
        [EnableCors("AllowSpecificOrigin")]
        [HttpPost]
        public async Task<ExecuteResult> GetTransactionStatus(string SeqNo, string NozzleId, string sn,string token,string FuelItemFdcReleaseTokenAttribute = "",string FuelItemOriginalGrossAmount = "",DateTime? FuelItemTransactionEndTime = null)
        {
            if (token != "123456789")
            {
                return null;
            }
            return await _PosTrxService.GetTransactionStatus( SeqNo,  NozzleId,  sn, FuelItemFdcReleaseTokenAttribute, FuelItemOriginalGrossAmount, FuelItemTransactionEndTime);
        }
        [Route("RemarkUnlockTransaction")]
        [EnableCors("AllowSpecificOrigin")]
        [HttpPost]
        public async Task<ExecuteResult> RemarkUnlockTransaction(PosTrxUnLockDto posTrxUnLock)
        {
         var dfsd =   HttpContext.Connection.RemoteIpAddress;
            DateTime? endTime = null;
            DateTime? unLockTime = null;
            DateTime? cancellation = null;
            if (!string.IsNullOrEmpty(posTrxUnLock.endTime))
            {
                endTime = DateTime.Parse(posTrxUnLock.endTime);
            }
            if (!string.IsNullOrEmpty(posTrxUnLock.unLockTime))
            {
                unLockTime = DateTime.Parse(posTrxUnLock.unLockTime);
            }
            if (!string.IsNullOrEmpty(posTrxUnLock.cancellation))
            {
                cancellation = DateTime.Parse(posTrxUnLock.cancellation);
            }
            return await _PosTrxService.RemarkUnlockTransaction(posTrxUnLock.userName, posTrxUnLock.alias, posTrxUnLock.ttc, posTrxUnLock.releaseToken, posTrxUnLock.nozzleNum , endTime, posTrxUnLock.oilName ,  posTrxUnLock.volume , posTrxUnLock.amount , unLockTime, posTrxUnLock.sn, posTrxUnLock.Comment, cancellation);
        }
    }
}
