package com.mosty.bkzx.sjjs.client;

import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.*;

@Service
public class AccountUtils {
    private static final Map<String, Accounts> accounts = new HashMap<String, Accounts>();

    AccountUtils() {
        accounts.put("5106", new Accounts("德阳", "zydytest", "system123", "5107", false, "510600000000", true, true));
    }

    /**
     * 获取建库的区域列表
     *
     * @return
     */
    public List<Map> getAccountList() {
        List<Map> _reslist = new ArrayList<>();
        Iterator<Map.Entry<String, Accounts>> _iter = accounts.entrySet().iterator();
        while (_iter.hasNext()) {
            Map.Entry<String, Accounts> _node = _iter.next();
            if (_node.getValue().hidden) {
                continue;
            }
            Map _tp = new HashMap();
            _tp.put("arecode", _node.getKey());
            _tp.put("name", _node.getValue().getName());
            _reslist.add(_tp);
        }
        return _reslist;
    }


    /**
     * 根据所选择的区域查找账户信息
     *
     * @return
     */
    public List<Accounts> findAccountsByArce(String arce) {
        if (StringUtils.isEmpty(arce)) {
            return null;
        }
        List<Accounts> _accounts = new ArrayList<>();
        Iterator<Map.Entry<String, Accounts>> _iter = accounts.entrySet().iterator();
        while (_iter.hasNext()) {
            Map.Entry<String, Accounts> entry = _iter.next();
            if (entry.getValue().getAreaCode().equals(arce)) {
                _accounts.add(entry.getValue());
            }
        }
        return _accounts;
    }


    public List<Accounts> findAccountsByArceAndName(String arce, String arceName) {
        if (StringUtils.isEmpty(arce) || StringUtils.isEmpty(arceName)) {
            return null;
        }
        List<Accounts> _accounts = new ArrayList<>();
        Iterator<Map.Entry<String, Accounts>> _iter = accounts.entrySet().iterator();
        while (_iter.hasNext()) {
            Map.Entry<String, Accounts> entry = _iter.next();
            if (entry.getValue().getAreaCode().equals(arce) && entry.getValue().getName().equals(arceName)) {
                _accounts.add(entry.getValue());
            }
        }
        return _accounts;
    }


    @Data
    public static class Accounts implements Serializable {
        private String name;
        private String account;
        private String pwd;
        private String areaCode;
        private boolean hidden;
        private String sssgajdm;
        private boolean isCarLibrary;
        private boolean isPeopleLibrary;

        public Accounts() {
        }

        public Accounts(String name, String account, String pwd, String areaCode, boolean hidden, String sssgajdm, boolean isCarLibrary, boolean isPeopleLibrary) {
            this.name = name;
            this.account = account;
            this.pwd = pwd;
            this.areaCode = areaCode;
            this.hidden = hidden;
            this.sssgajdm = sssgajdm;
            this.isCarLibrary = isCarLibrary;
            this.isPeopleLibrary = isPeopleLibrary;
        }
    }

}
