package com.cym.utils;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Component;

@Component
public class MenuUtils {
	// List<MenuCategory> menuCategoryList;

	public List<MenuCategory> getAll() {
		List<MenuCategory> menuCategoryList = new ArrayList<>();
		// DNS管理
		MenuCategory menuCategory = new MenuCategory("DNS管理", "other");
		menuCategory.getMenus().add(new Menu("adminPage/dns?pageSize=50", "DNS管理"));
		menuCategory.getMenus().add(new Menu("adminPage/hwKey?pageSize=20", "华为key管理"));
		menuCategory.getMenus().add(new Menu("adminPage/lineGroup?pageSize=20", "线路组"));
		menuCategory.getMenus().add(new Menu("adminPage/lineRoute?pageSize=20", "线路组解析"));
		menuCategoryList.add(menuCategory);

		// 服务器管理
		menuCategory = new MenuCategory("服务器管理", "system");
		menuCategory.getMenus().add(new Menu("adminPage/node?pageSize=50", "节点管理"));
		menuCategory.getMenus().add(new Menu("adminPage/nodeStatus?pageSize=50", "节点状态"));
		menuCategory.getMenus().add(new Menu("adminPage/property?pageSize=50", "资产管理"));
		menuCategory.getMenus().add(new Menu("adminPage/area?pageSize=20", "地域管理"));
		menuCategory.getMenus().add(new Menu("adminPage/ruleTab?", "缓存规则"));
		menuCategory.getMenus().add(new Menu("adminPage/ip?pageSize=20", "IP管理"));
		menuCategory.getMenus().add(new Menu("adminPage/task?pageSize=20", "同步任务"));
		menuCategoryList.add(menuCategory);

		// 站点管理
		menuCategory = new MenuCategory("站点管理", "user");
		menuCategory.getMenus().add(new Menu("adminPage/domainAdmin?pageSize=20", "域名列表"));
		menuCategory.getMenus().add(new Menu("adminPage/upstreamAdmin?pageSize=20", "四层转发"));
		menuCategory.getMenus().add(new Menu("adminPage/certAdmin?pageSize=20", "证书列表"));
		menuCategory.getMenus().add(new Menu("adminPage/dnsApi?pageSize=20", "DNS API"));
		menuCategory.getMenus().add(new Menu("adminPage/transfer?pageSize=20", "中转管理"));
		menuCategory.getMenus().add(new Menu("adminPage/statsTab?", "数据统计"));
		menuCategory.getMenus().add(new Menu("adminPage/domainRank?", "域名排行"));
		menuCategory.getMenus().add(new Menu("adminPage/refresh?", "刷新缓存"));
		menuCategoryList.add(menuCategory);

		// 套餐管理
		menuCategory = new MenuCategory("套餐管理", "product");
		menuCategory.getMenus().add(new Menu("adminPage/product?pageSize=20", "套餐管理"));
		menuCategory.getMenus().add(new Menu("adminPage/orderAdmin?pageSize=20", "售出套餐"));
		menuCategory.getMenus().add(new Menu("adminPage/customOrder?pageSize=20", "自定义套餐"));
		menuCategoryList.add(menuCategory);

		// IDC管理
		menuCategory = new MenuCategory("IDC管理", "product");
		menuCategory.getMenus().add(new Menu("adminPage/machineOrderAdmin?pageSize=20", "售出主机"));
		menuCategory.getMenus().add(new Menu("adminPage/machine?pageSize=50", "服务器产品"));
		menuCategory.getMenus().add(new Menu("adminPage/machineVps?pageSize=50", "云主机产品"));
		menuCategory.getMenus().add(new Menu("adminPage/machineRoom?pageSize=20", "机房管理"));
		menuCategory.getMenus().add(new Menu("adminPage/machineProvider?pageSize=20", "供应商管理"));
		menuCategory.getMenus().add(new Menu("adminPage/icp?pageSize=20", "ICP白名单"));
		menuCategoryList.add(menuCategory);

		// 财务管理
		menuCategory = new MenuCategory("财务管理", "user");
		menuCategory.getMenus().add(new Menu("adminPage/consumeRecord?pageSize=20", "消费充值记录"));
		menuCategoryList.add(menuCategory);

		// 用户管理
		menuCategory = new MenuCategory("用户管理", "user");
		menuCategory.getMenus().add(new Menu("adminPage/user?pageSize=20", "用户管理"));
		menuCategory.getMenus().add(new Menu("adminPage/admin?pageSize=20", "管理员管理"));
		menuCategory.getMenus().add(new Menu("adminPage/level?pageSize=20", "用户等级管理"));
		menuCategory.getMenus().add(new Menu("adminPage/workOrder?pageSize=20", "工单管理"));
		menuCategoryList.add(menuCategory);

		// 系统设置
		menuCategory = new MenuCategory("系统设置", "system");
		menuCategory.getMenus().add(new Menu("adminPage/errorPage?", "错误页面"));
		menuCategory.getMenus().add(new Menu("adminPage/quartzJob?pageSize=50", "定时任务"));
		menuCategoryList.add(menuCategory);

		// 日志管理
		menuCategory = new MenuCategory("日志管理", "other");
		menuCategory.getMenus().add(new Menu("adminPage/dnsOperationLog?pageSize=50", "DNS操作日志"));
		menuCategory.getMenus().add(new Menu("adminPage/operationLog?pageSize=50", "操作日志"));
		menuCategory.getMenus().add(new Menu("adminPage/domainFreeCheck?pageSize=50", "违规监控"));
		menuCategory.getMenus().add(new Menu("adminPage/checkLog?pageSize=50", "监控记录"));
		menuCategory.getMenus().add(new Menu("adminPage/checkLogRank?pageSize=50", "监控排行"));
		menuCategoryList.add(menuCategory);

		// 邮件管理
		menuCategory = new MenuCategory("邮件管理", "other");
		menuCategory.getMenus().add(new Menu("adminPage/emailSendLog?pageSize=20", "邮件日志"));
		menuCategory.getMenus().add(new Menu("adminPage/emailTemplate?pageSize=20", "邮件模板"));
		menuCategory.getMenus().add(new Menu("adminPage/telegramSendLog?pageSize=20", "Telegram日志"));
		menuCategoryList.add(menuCategory);

		return menuCategoryList;
	}

	public List<MenuCategory> getByUrls(List<String> urls) {
		List<MenuCategory> menuCategoryUsers = getAll();

		for (MenuCategory menuCategory : menuCategoryUsers) {
			for (Menu menu : menuCategory.getMenus()) {
				menu.setShow(false);
				if (urls.contains(menu.getUrl())) {
					menu.setShow(true);
				}
			}
		}

		return menuCategoryUsers;
	}

	public List<Menu> getAllMenu() {
		List<Menu> menus = new ArrayList<>();
		for (MenuCategory menuCategory : getAll()) {
			menus.addAll(menuCategory.getMenus());
		}

		return menus;
	}

	/**
	 * 菜单分类
	 * 
	 * @author CYM
	 *
	 */
	public static class MenuCategory implements Serializable {
		private static final long serialVersionUID = 3175408543485317759L;

		private String name;

		private String group;

		private List<Menu> menus;

		public MenuCategory(String name, String group) {
			this.name = name;
			this.group = group;
			this.menus = new ArrayList<>();

		}

		public String getGroup() {
			return group;
		}

		public void setGroup(String group) {
			this.group = group;
		}

		public String getName() {
			return name;
		}

		public void setName(String name) {
			this.name = name;
		}

		public List<Menu> getMenus() {
			return menus;
		}

		public void setMenus(List<Menu> menus) {
			this.menus = menus;
		}

		public static long getSerialversionuid() {
			return serialVersionUID;
		}

	}

	/**
	 * 菜单
	 * 
	 * @author CYM
	 *
	 */
	public static class Menu implements Serializable {
		private static final long serialVersionUID = 6848241258354172694L;

		private String url;
		private String name;
		private Boolean show;

		public Menu(String url, String name) {
			this.url = url;
			this.name = name;
			this.show = true;
		}

		public Boolean getShow() {
			return show;
		}

		public void setShow(Boolean show) {
			this.show = show;
		}

		public String getUrl() {
			return url;
		}

		public void setUrl(String url) {
			this.url = url;
		}

		public String getName() {
			return name;
		}

		public void setName(String name) {
			this.name = name;
		}

	}

}
