package com.yeejoin.amos.boot.module.tzs.biz.controller;

import com.yeejoin.amos.boot.biz.common.controller.BaseController;
import com.yeejoin.amos.boot.module.tzs.api.service.TzsAuthService;
import com.yeejoin.amos.feign.privilege.Privilege;
import com.yeejoin.amos.feign.privilege.model.AgencyUserModel;
import com.yeejoin.amos.feign.systemctl.Systemctl;
import com.yeejoin.amos.feign.systemctl.model.RegionModel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.typroject.tyboot.core.foundation.enumeration.UserType;
import org.typroject.tyboot.core.restful.doc.TycloudOperation;
import org.typroject.tyboot.core.restful.utils.ResponseHelper;
import org.typroject.tyboot.core.restful.utils.ResponseModel;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * 特种设备权限controller
 */
@RestController
@Api(tags = "特种设备权限Api")
@RequestMapping(value = "/tzs-auth-api")
public class TzsAuthController extends BaseController {



	@Autowired
	TzsAuthService tzsAuthService;

	/**
	 * 判断用户是否是管理员
	 * @return
	 */
	@TycloudOperation(ApiLevel = UserType.AGENCY)
	@GetMapping(value = "/isUserAdmin")
	@ApiOperation(httpMethod = "GET", value = "判断用户是否是管理员", notes = "判断用户是否是管理员")
	public ResponseModel<Boolean> isUserAdmin() {
		Boolean flag = false;
		AgencyUserModel me = Privilege.agencyUserClient.getme().getResult();
		if(me.getUserName().equals("tzs_wjl")) {
			flag = true;
		}
		return ResponseHelper.buildResponse(flag);
	}

	/**
	 *  获取用户regionCode
	 */
	@TycloudOperation(ApiLevel = UserType.AGENCY)
	@GetMapping(value = "/getUserRegincode")
	@ApiOperation(httpMethod = "GET", value = "获取用户regionCode", notes = "获取用户regionCode")
	public ResponseModel<List<String>> getUserRegincode() {
		List<String> regionList = tzsAuthService.getUserRegionCode();
		AgencyUserModel me = Privilege.agencyUserClient.getme().getResult();
		return ResponseHelper.buildResponse(regionList);
	}

	/**
	 *  获取用户组织机构树
	 */
	@TycloudOperation(ApiLevel = UserType.AGENCY)
	@GetMapping(value = "/getUserReginTree")
	@ApiOperation(httpMethod = "GET", value = "获取用户组织机构树", notes = "获取用户组织机构树")
	public ResponseModel<Collection<RegionModel>> getUserReginTree() {
		List<RegionModel> result = tzsAuthService.getUserReginTree();
		return ResponseHelper.buildResponse(result);
	}



}
