package com.seeyon.apps.src_ydctdatasync.datamap;


import com.seeyon.apps.src_ydctdatasync.utils.EnumMapUtils;
import com.seeyon.apps.src_ydctdatasync.utils.TimeUtils;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;
import java.util.function.Function;

public class ContractBillMode extends AbstractFeeDataMapMode{


    @Override
    public void preProcess(Map<String, Object> map) {
        String recordBill = EnumMapUtils.getEnumItemValue(zcRootPcode,agent,"是否入账","未入");
        String incomeOrCost = EnumMapUtils.getEnumItemValue(zcRootPcode,agent,"收支类型","收");
        String billType = (String) map.get("bill_type");
        if("宽带".equals(billType)) {
            map.put("bill_type","宽带费");
        } else if("宽带或物业费".equals(billType)) {
            map.put("bill_type","物业费");
        } else if("月租金".equals(billType)) {
            map.put("bill_type","租金");
        } else if("物业".equals(billType)) {
            map.put("bill_type","物业费");
        } else if("水电余额".equals(billType)) {
            map.put("bill_type","水电费");
        }
        String feeType = EnumMapUtils.getEnumItemValue(zcRootPcode,agent,"住保-费用类型",  map.get("bill_type") + "");
        if("".equals(feeType)) {
            feeType = EnumMapUtils.getEnumItemValue(zcRootPcode,agent,"住保-费用类型",  "其他");
        }
        map.put("recordBill",recordBill);
        map.put("bill_type",feeType);
        map.put("incomeOrCost",incomeOrCost);
    }

    @Override
    public Map<String, Function<Object, Object>> getFieldProcessors() {
        return null;
    }

    @Override
    public boolean support() {
        return false;
    }

    @Override
    public void transfer(Object target, Object source) {
        commonAttrTransfer(target,source);
        Map<String, Object> targetMap = (Map<String, Object>) target;
        Map<String, Object> sourceMap = (Map<String, Object>) source;
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        targetMap.put("是否入账",sourceMap.get("recordBill")); //填充是否入账
        targetMap.put("收支类型",sourceMap.get("incomeOrCost")); //填充收支类型
        targetMap.put("住保-费用类型",sourceMap.get("bill_type")); //填充费用类型
        targetMap.put("住保-主键",sourceMap.get("bill_id")); //主键
        targetMap.put("应收金额",sourceMap.get("bill_amount")); //填充应收金额
        targetMap.put("本次实收金额",sourceMap.get("bill_amount")); //填充本次实收金额
        try {
            targetMap.put("住保-账单生成日期",df.format(TimeUtils.convertLocalDateTime2Date(sourceMap.get("trade_reconciliation_time")))); //填充账单生成日期
        }catch (NullPointerException e) {

        }
    }

}
