package com.brilliance.isc.common.setfeg.fee;

import lombok.Getter;
import lombok.Setter;

import java.util.*;

import static com.brilliance.mda.runtime.mda.Constants.TAB;

public class FeeSet {
    private LinkedHashMap<String, FeeEntity> feeEntityList = new LinkedHashMap();
    private LinkedHashMap<String, FeeEntity> fepEntityList = new LinkedHashMap<>();
    private Map<String, Setpty> setptyMap = new LinkedHashMap<>();
    private Map<String, Setcbs> setcbsMap = new LinkedHashMap<>();
    private Map<String, Wrksum> wrksumMap = new LinkedHashMap<>();
    //国内证业务标识
    @Getter
    @Setter
    private String dflg;

    //外管局账户性质
    @Getter
    @Setter
    private String actpro;

    public void addFeeEntity(String feeId, FeeEntity feeEntity) {
        feeEntityList.put(feeId, feeEntity);
    }

    public List<String> getAllFeeInrs() {
        return new ArrayList<>(feeEntityList.keySet());
    }

    public List<String> getAllFepInrs() {
        return new ArrayList<>(fepEntityList.keySet());
    }

    public List<FeeEntity> getAllFeeEntity() {
        List<FeeEntity> allFeeEntity = new ArrayList<>();
        allFeeEntity.addAll(feeEntityList.values());

        return allFeeEntity;
    }

    public List<FeeEntity> getAllFepEntity() {
        List<FeeEntity> allFeeEntity = new ArrayList<>();
        allFeeEntity.addAll(fepEntityList.values());

        return allFeeEntity;
    }

    public List<FeeEntity> getAllEntity() {
        List<FeeEntity> allFeeEntity = new ArrayList<>();
        allFeeEntity.addAll(feeEntityList.values());
        allFeeEntity.addAll(fepEntityList.values());
        return allFeeEntity;
    }


    public void putSetpty(String key, Setpty setpty) {
        setptyMap.put(key, setpty);
    }

    public Setpty getSetpty(String key) {
        return setptyMap.get(key);
    }

    public void clearSetpty() {
        this.setptyMap.clear();
    }

    public FeeEntity getFeeEntityById(String id) {
        FeeEntity feeEntity = feeEntityList.get(id);
        if (feeEntity == null) {
            feeEntity = fepEntityList.get(id);
        }
        return feeEntity;
    }

    public List<Setpty> getAllSetpty() {
        return new ArrayList<>(setptyMap.values());
    }


    public Setcbs getSetcbs(String key) {
        return setcbsMap.get(key);
    }

    public Setcbs putSetcbs(String key, Setcbs setcbs) {
        return setcbsMap.put(key, setcbs);
    }

    public void removeSetCbs(String modId) {
        this.setcbsMap.keySet().removeIf(key -> key.startsWith(modId + TAB));
    }

    public void putWrksum(String key, Wrksum wrksum) {
        wrksumMap.put(key, wrksum);
    }

    public Wrksum getWrksum(String key) {
        return wrksumMap.get(key);
    }

    public Map<String, Wrksum> getWrksumMap() {
        return this.wrksumMap;
    }

    public List<Wrksum> getWrksumByBlurKey(String blurKey) {
        List<Wrksum> list = new ArrayList<>();
        Set<String> keys = this.wrksumMap.keySet();
        for (String k : keys) {
            if (k.indexOf(blurKey) > -1) {
                list.add(this.wrksumMap.get(k));
            }
        }
        return list;
    }

    public void clearWrksum(String wrksumKey) {
        this.wrksumMap.keySet().removeIf(key -> key.contains(wrksumKey));
    }

    public void clearFeeEntity(String feeEntityKey) {
        feeEntityList.keySet().removeIf(key -> key.contains(feeEntityKey));
    }

    public List<Wrksum> getAllWrksum() {
        return new ArrayList<>(wrksumMap.values());
    }

    public List<Setcbs> getAllSetcbs() {
        return new ArrayList<>(setcbsMap.values());
    }

    public void putFeeEntity(String id, FeeEntity feeEntity) {
        feeEntityList.put(id, feeEntity);
    }

    public void putFepEntity(String inr, FeeEntity feeEntity) {
        feeEntityList.put(inr, feeEntity);
    }

}
