package com.platform.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
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.bytedeco.javacpp.presets.opencv_core;
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("/deleteStaff")
    public Result deleteStaff(@RequestBody JSONObject param) {
        Long userId = param.getLong("userId");
        Long toUserId = param.getLong("toUserId");
        String toUserPone = param.getString("toUserPone");
        // 获取直播间绑定信息
        List<Long> bindUsers = mySysUserBrandService.queryBrandIdList(userId);
        if (!ObjectUtils.isEmpty(bindUsers)) {
           mySysUserBrandService.reBindUser(userId,toUserId,toUserPone);
        }
        return Result.success();
    }
    @PostMapping("/getCanShow")
    public Result getCanShow(@RequestBody JSONObject param) {
        Object userIds = param.get("userIds");
        List<Integer> jsonArray = (List<Integer>) userIds;
        Integer brandId = (Integer) param.get("brandId");
        HashMap<Long,Integer> resultMap = new HashMap<>();
        for (Integer userId : jsonArray) {
            SysUserBrand userBrand = mySysUserBrandService.getUserBrandById(Long.valueOf(userId), brandId);
            if(userBrand!=null){
                resultMap.put(userBrand.getUserId(),userBrand.getCanShow());
            }
        }
        return Result.success(resultMap);
    }



}
