package com.xingxi.api.service;

import com.xingxi.api.common.UserContext;
import com.xingxi.business.Order.domain.Order;
import com.xingxi.common.utils.DateUtils;

import javax.servlet.http.HttpServletRequest;
import java.text.ParseException;
import java.util.Calendar;
import java.util.Date;

public interface WXPayServiceI {
    String expTimeFormat = "yyyy-MM-dd'T'HH:mm:ss+08:00";

    Object unifiedOrder(Long callWXPayMercId, UserContext userContext, Order order) throws Exception;

    Object continue2pay(Long callWXPayMercId, UserContext userContext, String prepayId) throws Exception;

    void callback(Long callWXPayMercId, HttpServletRequest request) throws Exception;


    default Date parseDate(String dateString){
        try {
            return DateUtils.parseDate(dateString, expTimeFormat);
        } catch (ParseException e) {
            throw new RuntimeException(e);
        }
    }

    default Date getCurrentDate(){
        Calendar instance = Calendar.getInstance();
        instance.set(Calendar.MILLISECOND, 0);
        return instance.getTime();
    }


    default String timeExpire(){
        return DateUtils.parseDateToStr(
                expTimeFormat, DateUtils.addMinutes(getCurrentDate(), 10));
    }

}
