package com.fs.huifuPay.dto;

import com.fs.common.DeviceUtils;
import lombok.Data;

import java.time.LocalDate;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;

/**
 * 请求头DTO
 * <p>
 * @author xdd
 * @date 2025-02-27
 */
@Data
public class TzReqHeaderDTO {

    /**
     * 终端类型
     * <p>
     * 示例值：WEB
     */
    private String cutType;

    /**
     * 终端号
     */
    private String terminalNo;

    /**
     * 交易日期
     * <p>
     * 格式：YYYYMMDD
     * 示例值：20250312
     */
    private String tranDate;

    /**
     * 交易流水号
     */
    private String tranSeq;

    /**
     * 交易时间
     *
     */
    private String tranTime;


    public static TzReqHeaderDTO getInstance(String tranSeq){
        if(tranSeq == null || tranSeq.trim().isEmpty()){
            throw new IllegalArgumentException("tranSeq 不能为空");
        }
        // 使用当前日期和时间
        DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyyMMdd");
        DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("HHmmssSSS");

        String macAddress = DeviceUtils.getMacAddress();
        if(macAddress == null || macAddress.trim().isEmpty()){
            throw new IllegalArgumentException("macAddress 不能为空");
        }
        TzReqHeaderDTO reqHeader = new TzReqHeaderDTO();
        reqHeader.setCutType("WEB");
        reqHeader.setTerminalNo(macAddress);
        reqHeader.setTranDate(LocalDate.now().format(dateFormatter));
        reqHeader.setTranSeq(tranSeq);
        reqHeader.setTranTime(LocalTime.now().format(timeFormatter));

        return reqHeader;
    }
}
