package com.neusoft.smart.pos.org.controller;


import com.neusoft.smart.pos.framework.constants.RoleConstant;
import com.neusoft.smart.pos.framework.dto.ResponseData;

import com.neusoft.smart.pos.framework.exception.BusinessCommonException;
import com.neusoft.smart.pos.org.constants.OrgShopErrorCode;
import com.neusoft.smart.pos.org.dto.User;
import com.neusoft.smart.pos.org.persistent.domain.UserExample;
import com.neusoft.smart.pos.org.service.ManageableGroupService;
import com.neusoft.smart.pos.utils.RequestHeaderUtil;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;

@RestController
@RequestMapping("/ManageableGroup")
public class ManageableGroupController {
    @Resource
    ManageableGroupService manageableGroupService;

    @GetMapping("/getManageableGroup")
    public ResponseData<?> getManageableGroup() {
        UserExample userExample = new UserExample();
        userExample.setId(RequestHeaderUtil.getUserId());
        User users = new User();
        Integer orgId = 0;
        users = manageableGroupService.getManageableGroup(userExample);
        if (StringUtils.isEmpty(users.getOrg())) throw new BusinessCommonException(OrgShopErrorCode.ROLE_IS_NULL);
        if (users.getOrg().equals(RoleConstant.ROLE_ADMIN)|| users.getOrg().equals(RoleConstant.ROLE_USER)) {
             orgId = RequestHeaderUtil.getOrgId();
        }

        return new ResponseData<>(orgId);
    }
}
