package com.hzya.frame.plugin.cinvoice.assembler;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.hzya.frame.plugin.cinvoice.lexmis.entity.LexmisPublicinfoEntity;
import com.hzya.frame.plugin.cinvoice.lexmis.entity.LexmiscivBusinvoiceEntity;

/**
 * @Description 客运汽车（a3）
 * @Author xiangerlin
 * @Date 2025/4/21 11:41
 **/
public class BusInvoiceAssembler implements ParamAssembler{

    private JSONObject jsonObject;

    public BusInvoiceAssembler(JSONObject jsonObject) {
        this.jsonObject = jsonObject;
    }

    /**
     * 组装参数
     *
     * @return
     */
    @Override
    public JSONObject assembleParam() {
        JSONObject param = new JSONObject();
        String busInvoiceStr = jsonObject.getString("busInvoice");
        String publicInfoiceStr = jsonObject.getString("publicInfoice");
        if (StrUtil.isNotEmpty(busInvoiceStr)){
            LexmiscivBusinvoiceEntity businvoiceEntity = JSONObject.parseObject(busInvoiceStr,LexmiscivBusinvoiceEntity.class);
            LexmisPublicinfoEntity publicinfo = JSONObject.parseObject(publicInfoiceStr,LexmisPublicinfoEntity.class);
            // 发票代码，必填
            param.put("fpdm", businvoiceEntity.getBI_FPDM());
            // 发票号码，必填
            param.put("fphm", businvoiceEntity.getBI_FPHM());
            // 乘车日期/开票时间，格式为 yyyy-MM-dd，必填
            param.put("ccrq", DateUtil.format(businvoiceEntity.getBI_DATE(),"yyyy-MM-dd"));
            // 乘车时间，格式为 HH:mm，非必填
            param.put("ccsj", businvoiceEntity.getBI_TIME());
            // 出发地，非必填
            param.put("cfd", businvoiceEntity.getBI_FSTATION());
            // 到达地，非必填
            param.put("ddd", businvoiceEntity.getBI_TSTATION());
            // 乘车人姓名，非必填
            param.put("ccrxm", businvoiceEntity.getBI_USERNAME());
            // 身份证号，非必填
            param.put("sfzh", businvoiceEntity.getBI_USERID());
            // 金额，必填
            param.put("je", businvoiceEntity.getBI_TOTALAMOUNT());
            // 发票消费类型，非必填
            param.put("fpxflx", "");
        }
        return param;
    }
}
