package com.smppw.common.pojo.enums.strategy;

import com.smppw.common.pojo.IStrategy;
import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;

/**
 * 新 - 第一级策略
 */
public enum Strategy implements IStrategy {

	/** 私募策略 新融智策略 **/
	Others(-1, "其它", "", ""),

	All(0, "全部", "", "IN00000008"),

	Equity(1001, "股票策略", "IN000002D2", "IN00000008"),

	Bond(1002, "债券策略", "IN000002D3", "IN00000077"),

	Future(1003, "期货及衍生品策略","IN000002D4", "IN0000008S"),

	Multiple(1004, "多资产策略","IN000002D5", "IN00000008"),

	Portfolio(1005,"组合基金", "IN000002D6", "IN00000008"),

	Rights(9, "权益类", "IN0000001B", "IN00000008"),

	/** 公募策略 **/
	Equity2(101, "股票","IN0000001C", "IN00000008"),

	OverseeFund(108, "海外","IN0000001C", "IN00000009"),

	Hybrid(102,"混合", "IN0000001J", "IN00000008"),

	Bond2(103, "债券","IN0000001H", "IN00000077"),

	Cash(104,"货币", "IN0000001H", "IN00000077"),

	Commodity(105, "商品","IN0000001E", "IN0000008S"),

	MarketNeutral(106, "市场中性","IN0000001G", "IN00000008"),

	FOF(107, "FOF","IN0000001G", "IN00000008"),

	Others2(-100, "其他","", "");

	private Integer id;
	private String nameDesc;
	private String rongZhiIndex;
	private String benchmark;

	private Strategy(Integer id, String nameDesc, String rongZhiIndex, String benchmark) {
		this.id = id;
		this.nameDesc = nameDesc;
		this.rongZhiIndex = rongZhiIndex;
		this.benchmark = benchmark;
	}

	public int getId() {
		return id;
	}

	public String getRongZhiIndex() {
		return rongZhiIndex;
	}

	public String getBenchmark() {
		return benchmark;
	}


	public String getNameDesc() {
		return nameDesc;
	}

	public static boolean isStrategy(String str) {
		if (StringUtils.isEmpty(str))
			return false;

		for (Strategy s : Strategy.values()) {
			if (str.equals(s.getId() + "") || str.equals(s.name())) {
				return true;
			}
		}

		return false;
	}

	public static Strategy getStrategy(Integer id) {
		return Stream.of(Strategy.values()).filter(e -> e.id.equals(id)).findFirst().orElse(null);
	}

	// 已修正
	/**新的策略归为原来的策略*/
	public static Strategy getOldStrategy(Integer id) {
		if(Math.abs(id) >= 100 && Math.abs(id) < 1000){
			switch (id) {
				case 101:
				case 108:
					return Strategy.Equity;
				case 102:
					return Strategy.Multiple;
				case 103:
				case 104:
					return Strategy.Bond;
				case 105:
					return Strategy.Future;
				case 106:
					return Strategy.Equity;	// 对应策略：股票 - 股票市场中性
				case 107:
					return Strategy.Portfolio;

				default:
					return Strategy.Others;
			}
		}
		return Stream.of(Strategy.values()).filter(e -> e.id.equals(id)).findFirst().orElse(null);
	}



	public static Strategy getStrategy(String id) {
		if (null == id){
			return null;
		}
		for(Strategy s : Strategy.values()){
			if(id.equals(s.getId()+"") || id.equals(s.name())){
				return s;
			}
		}
		return null;
	}

	public static Strategy getStrategyByName(String name) {
		if (null == name){
			return null;
		}
		for(Strategy s : Strategy.values()){
			if(name.equals(s.getNameDesc()+"")){
				return s;
			}
		}
		return null;
	}

	public static Strategy getStrategyByRongZhiIndex(String rongZhiIndex) {
		return Stream.of(Strategy.values()).filter(e -> e.rongZhiIndex.equals(rongZhiIndex)).findFirst().orElse(null);
	}

	// 已修正
	//	1-股票策略，2-宏观策略，3-管理期货，4-事件驱动，5-相对价值策略，6-债券策略，7-组合基金，8-复合策略，-1-其它策略
	private static final Map<String, String> EIGHT_TRATEGY_NAME_MAP = new HashMap<>();
	static {
		EIGHT_TRATEGY_NAME_MAP.put("1001", "股票策略");
		EIGHT_TRATEGY_NAME_MAP.put("1002", "债券策略");
		EIGHT_TRATEGY_NAME_MAP.put("1003", "期货及衍生品策略");
		EIGHT_TRATEGY_NAME_MAP.put("1004", "多资产策略");
		EIGHT_TRATEGY_NAME_MAP.put("1005", "组合基金");
		EIGHT_TRATEGY_NAME_MAP.put("-1", "其它策略");

		EIGHT_TRATEGY_NAME_MAP.put("101", "股票");
		EIGHT_TRATEGY_NAME_MAP.put("102", "混合");
		EIGHT_TRATEGY_NAME_MAP.put("103", "债券");
		EIGHT_TRATEGY_NAME_MAP.put("104", "货币");
		EIGHT_TRATEGY_NAME_MAP.put("105", "商品");
		EIGHT_TRATEGY_NAME_MAP.put("106", "市场中性");
		EIGHT_TRATEGY_NAME_MAP.put("107", "FOF");
		EIGHT_TRATEGY_NAME_MAP.put("108", "海外");
		EIGHT_TRATEGY_NAME_MAP.put("-100", "其他");

	}

	public static String getStrategyName(String stragegyId, String defaultValue) {
		return EIGHT_TRATEGY_NAME_MAP.getOrDefault(stragegyId, defaultValue);
	}


	public static final List<Strategy> STRATEGY_LIST = Arrays.asList(All, Equity, Bond, Future, Multiple, Portfolio, Equity2,
			OverseeFund, Hybrid, Bond2, Cash, Commodity, MarketNeutral, FOF);

	public static final List<Strategy> EIGHT_STRATEGY = Arrays.asList(Equity, Future, Bond, Portfolio, Multiple);

	public static final List<Strategy> EIGHT_STRATEGY_WITH_RIGHTS = Arrays.asList(Equity, Bond, Future, Multiple, Portfolio);

	public static final List<Strategy> EIGHT_STRATEGY_WITH_OTHERS = Arrays.asList(Equity, Bond, Future, Multiple, Portfolio, Others);

	/** 新添加了公募基金策略 */
	public static final List<Strategy> NEW_STRATEGY_WITH_OTHERS = Arrays.asList(Equity, Bond, Future, Multiple, Portfolio, Others,
			Equity2, OverseeFund, Hybrid, Bond2, Cash, Commodity, MarketNeutral, FOF, Others2);

	public static final List<Strategy> STRATEGY_WITHOUT_OTHERS = Arrays.asList(All, Equity, Bond, Future, Multiple, Portfolio);

	// 公募策略集合
	public static final List<Strategy> PUBLIC_STRATEGY = Arrays.asList(All,Equity2, OverseeFund, Hybrid, Bond2, Cash, Commodity, MarketNeutral, FOF, Others2);
	// 公募策略id集合
	public static final List<Integer> PUBLIC_STRATEGY_ID_LIST = Arrays.asList(All.getId(),Equity2.getId(), OverseeFund.getId(), Hybrid.getId(),
			Bond2.getId(), Cash.getId(), Commodity.getId(), MarketNeutral.getId(), FOF.getId(), Others2.getId());

//	public static Map<Strategy, List<Strategy.RzSubstrategy>> rzStrategySubstrategy() {
//		return StrategyDao.getInstance().rzStrategySubstrategy();
//	}

	@Override
	public Integer getStrategyId() {
		return this.getId();
	}

	@Override
	public String getStrategyOriginName() {
		return this.name();
	}

	@Override
	public String getStrategyNameDesc() {
		return this.getNameDesc();
	}



	public class RzSubstrategy {
		private String substrategyId;
		private String indexId;
		private String indexCode;

		public RzSubstrategy(String substrategyId, String indexCode, String indexId) {
			super();
			this.substrategyId = substrategyId;
			this.indexCode = indexCode;
			this.indexId = indexId;
		}

		public String getSubstrategyId() {
			return substrategyId;
		}

		public void setSubstrategyId(String substrategyId) {
			this.substrategyId = substrategyId;
		}

		public String getIndexId() {
			return indexId;
		}

		public void setIndexId(String indexId) {
			this.indexId = indexId;
		}

		public String getIndexCode() {
			return indexCode;
		}

		public void setIndexCode(String indexCode) {
			this.indexCode = indexCode;
		}
	}
	
}
