package com.fdkankan.platform.feign;

import com.fdkankan.platform.goods.entity.Camera;
import com.fdkankan.platform.goods.entity.CameraDetail;
import com.fdkankan.platform.goods.service.ICameraDetailService;
import com.fdkankan.platform.goods.service.ICameraService;
import com.fdkankan.scene.api.feign.SceneUserSceneClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 提供场景调用
 */
@RestController
@RequestMapping("/feign/goods")
public class GoodsFeign {

    private static Logger log = LoggerFactory.getLogger("feignVisitLog");

    @Autowired
    private ICameraService cameraService;
    @Autowired
    private ICameraDetailService cameraDetailService;
    @Autowired
    private SceneUserSceneClient sceneUserSceneClient;

    @PostMapping("/getCameraByChildName")
    public Camera getCameraByChildName(@RequestParam(value = "childName", required = false) String childName) {
        Camera camera = cameraService.getByChildName(childName);
        return camera;
    }

    @PostMapping("/getCameraDetailByCameraId")
    public CameraDetail getCameraDetailByCameraId(@RequestParam(value = "cameraId", required = false) Long cameraId) {
        CameraDetail detail = cameraDetailService.getByCameraId(cameraId);
        return detail;
    }

    @PostMapping("/updateCameraDetailByCameraIdAndSpace")
    public CameraDetail updateCameraDetailByCameraIdAndSpace(@RequestParam(value = "cameraId", required = false) Long cameraId,
                                                             @RequestParam(value = "space", required = false) Long space) {
        CameraDetail detail = cameraDetailService.updateCameraDetailByCameraIdAndSpace(cameraId,space);
        return detail;
    }

    @PostMapping("/getCameraBySnCode")
    public Camera getCameraBySnCode(@RequestParam(value = "snCode", required = false) String snCode) {
        Camera detail = cameraService.getBySnCode(snCode);
        return detail;
    }

    @PostMapping("/getByChildNameAndChildPassword")
    public Camera getByChildNameAndChildPassword(@RequestParam(value = "appUserName") String appUserName,
                                                  @RequestParam(value = "appPassword") String appPassword) {
        Camera camera = cameraService.getByChildNameAndChildPassword(appUserName, appPassword);
        return camera;
    }

    @PostMapping("/findByChildNameAndChildPassword")
    public Camera findByChildNameAndChildPassword(@RequestParam(value = "appUserName") String appUserName,
                                                  @RequestParam(value = "appPassword") String appPassword) {
        Camera camera = cameraService.getByChildNameAndChildPassword(appUserName, appPassword);
        return camera;
    }

    @PostMapping("/getCameraById")
    public Camera getCameraById(@RequestParam(value = "cameraId") Long cameraId) {
        Camera camera = cameraService.getAvailableById(cameraId);
        return camera;
    }

    @PostMapping("/getCameraLikeSnCode")
    List<Camera> getCameraLikeSnCode(@RequestParam(value = "searchKey")String searchKey){
        List<Camera> cameraList = cameraService.getCameraLikeSnCode(searchKey);
        return cameraList;
    }

}

