package com.neusoft.smart.pos.gateway.service;


import com.neusoft.smart.pos.constants.DictionaryConstant;
import com.neusoft.smart.pos.dto.member.request.MemberRechargeRequest;
import com.neusoft.smart.pos.dto.member.request.MemberRefundRequest;
import com.neusoft.smart.pos.dto.member.request.MemberTransactionRequest;
import com.neusoft.smart.pos.dto.member.response.DetailedMemberResponse;
import com.neusoft.smart.pos.dto.org.response.PostShopResponse;
import com.neusoft.smart.pos.dto.promotion.request.GetPreferentialPriceRequest;
import com.neusoft.smart.pos.dto.promotion.response.GetPreferentialPriceResponse;
import com.neusoft.smart.pos.dto.trade.request.*;
import com.neusoft.smart.pos.dto.trade.response.*;
import com.neusoft.smart.pos.framework.constants.ApplicationConstants;
import com.neusoft.smart.pos.framework.dto.ResponseData;
import com.neusoft.smart.pos.framework.exception.BusinessCommonException;
import com.neusoft.smart.pos.framework.task.TaskExecutor;
import com.neusoft.smart.pos.framework.utils.BeanUtil;
import com.neusoft.smart.pos.framework.utils.DateUtils;
import com.neusoft.smart.pos.gateway.constants.MemberErrorCode;
import com.neusoft.smart.pos.gateway.service.feignService.*;
import com.neusoft.smart.pos.gateway.task.RecordOrderTask;
import com.neusoft.smart.pos.redis.bean.DeviceInfo;
import com.neusoft.smart.pos.utils.PosDeviceRedisUtils;
import com.neusoft.smart.pos.utils.PosMemberRedisUtils;
import lombok.val;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Service("facePayService")
public class FacePayService {
    
   
    @Autowired
    private RemoteFacePayService remoteFacePayService;
    
    @Autowired
    private RemoteShopService remoteShopService;
    
    /**
     * 人脸支付初始化方法
     *
     * @return
     */
    public PostInitFacePayResponse initFacePay(PostInitFacePayRequest initFacePayRequest) {
        DeviceInfo deviceInfo = PosDeviceRedisUtils.getDeviceInfoBySerialNo(initFacePayRequest.getSerialNo());
        if (null == deviceInfo) {
            throw new BusinessCommonException(MemberErrorCode.MEMBER_CARD_NOT_EXIST);
        }
        ResponseData<PostShopResponse> shopResponseData = remoteShopService.getShopDetail(deviceInfo.getStoreId());
        initFacePayRequest.setStoreName(shopResponseData.getResult().getName());
        initFacePayRequest.setStoreId(deviceInfo.getStoreId().toString());
        initFacePayRequest.setDeviceId(initFacePayRequest.getSerialNo());
        val initFacePayResponseData = remoteFacePayService.initFacePay(initFacePayRequest);
        if (null == initFacePayResponseData || !ApplicationConstants.SUCCESS_CODE.equals(initFacePayResponseData.getCode())) {
            throw new BusinessCommonException(initFacePayResponseData);
        }
        return initFacePayResponseData.getResult();
    }
    
    /**
     * 人脸生活初始化方法
     *
     * @return
     */
    public PostInitFacePayResponse initFaceLive(PostInitFacePayRequest initFacePayRequest) {
        val initFaceLiveResponseData = remoteFacePayService.initFaceLive(initFacePayRequest);
        if (null == initFaceLiveResponseData || !ApplicationConstants.SUCCESS_CODE.equals(initFaceLiveResponseData.getCode())) {
            throw new BusinessCommonException(initFaceLiveResponseData);
        }
        return initFaceLiveResponseData.getResult();
    }
    
}
