package com.fdkankan.ucenter.controller.api;

import com.fdkankan.common.exception.BusinessException;
import com.fdkankan.ucenter.common.BaseController;
import com.fdkankan.ucenter.common.Result;
import com.fdkankan.ucenter.constant.LoginConstant;
import com.fdkankan.ucenter.service.IVaildCamerasService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 本地化版本获取每个公司可使用的相机
 * 消安 使用接口
 * Created by Hb_zzZ on 2020/4/2.
 */
@Log4j2
/**本地化版本获取每个公司可使用的相机*/
@RestController
@RequestMapping("/ucenter/vaild/cameras")
public class VaildCamerasController extends BaseController {

    @Autowired
    private IVaildCamerasService vaildCameraService;

    /**
     * 获取企业可用相机列表
     * @param
     * @return
     */
    @RequestMapping(value = "/getVaildCameras")
    public Result getVaildCameras() throws Exception{
        String file = request.getParameter("file");
        String companyName = request.getParameter("companyName");
        if(StringUtils.isEmpty(file) || StringUtils.isEmpty(companyName)){
            log.info("file:" + file);
            log.info("companyName:" + companyName);
            throw new BusinessException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
        }

        return vaildCameraService.getVaildCameras(file, companyName);
    }

    /**
     * 新增企业可用相机列表
     * @param
     * @return
     */
    @RequestMapping(value = "/addVaildCameras")
    public Result addVaildCameras() throws Exception{
        String companyName = request.getParameter("companyName");
        String macId = request.getParameter("macId");
        String wifiName = request.getParameter("wifiName");

        if(StringUtils.isEmpty(macId) || StringUtils.isEmpty(companyName)){
            log.info("macId:" + macId);
            log.info("companyName:" + companyName);
            throw new BusinessException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
        }

        return vaildCameraService.addVaildCameras(macId, companyName, wifiName);
    }

    /**
     * 删除企业可用相机列表
     * @param
     * @return
     */
    @RequestMapping(value = "/deleteVaildCameras")
    public Result deleteVaildCameras() throws Exception{
        String companyName = request.getParameter("companyName");
        String macId = request.getParameter("macId");

        if(StringUtils.isEmpty(macId) || StringUtils.isEmpty(companyName)){
            log.info("macId:" + macId);
            log.info("companyName:" + companyName);
            throw new BusinessException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
        }

        return vaildCameraService.deleteVaildCameras(macId, companyName);
    }

}
