package com.platform.controller;

import com.platform.entity.Result;
import com.platform.entity.SysUserBrand;
import com.platform.service.custom.MySysUserBrandService;
import com.platform.service.impl.ZhiHouseService;
import com.platform.vos.TbUser;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/zfb")
public class ZfbController {

    @Autowired
    private MySysUserBrandService mySysUserBrandService;

    @Autowired
    private ZhiHouseService zhiHouseService;

    @PostMapping("/preDeleteStaff")
    public Result preDeleteStaff(@RequestBody HashMap<String,Long> param) {
        Long userId = param.get("userId");
        Long deptId = param.get("deptId");
        // 获取直播间绑定信息
        List<Long> bindUsers = mySysUserBrandService.queryBrandIdList(userId);
        if (!ObjectUtils.isEmpty(bindUsers)) {
            // 获取该公司下管理员手机号
            List<TbUser> userEntities = zhiHouseService.getSysUserListByDeptIds(deptId);
            List<String> phones = userEntities.stream().filter(user -> !user.getId().equals(userId))
                    .map(TbUser::getPhone).collect(Collectors.toList());
            if(ObjectUtils.isEmpty(phones)){
                return Result.failure("删除失败，公司仅剩一名员工，不可进行删除！");
            }
            return Result.success(phones);
        }
        return Result.success();
    }
    @PostMapping("/getCanShow")
    public Result getCanShow(@RequestBody HashMap<String,Long> param) {
        Long userId = param.get("userId");
        Integer brandId = Math.toIntExact(param.get("brandId"));
        SysUserBrand userBrandById = mySysUserBrandService.getUserBrandById(userId, brandId);
        if(userBrandById == null){
            return Result.failure("暂无数据");
        }
        return Result.success(userBrandById.getCanShow());
    }



}
