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 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;

    @PostMapping("/getCameraByChildName")
    public Camera getCameraByChildName(@RequestParam(value = "childName", required = false) String childName) {
        log.info("scene服务调用:getCameraByChildName,参数：childName:{},",childName);
        Camera camera = cameraService.getByChildName(childName);
        log.info("scene服务调用:getCameraByChildName,返回:{}",camera);
        return camera;
    }

    @PostMapping("/getCameraDetailByCameraId")
    public CameraDetail getCameraDetailByCameraId(@RequestParam(value = "cameraId", required = false) Long cameraId) {
        log.info("scene服务调用:getCameraDetailByCameraId,参数：cameraId:{},",cameraId);
        CameraDetail detail = cameraDetailService.getByCameraId(cameraId);
        log.info("scene服务调用:getCameraDetailByCameraId,返回:{}",detail);
        return detail;
    }

    @PostMapping("/updateCameraDetailByCameraIdAndSpace")
    public CameraDetail updateCameraDetailByCameraIdAndSpace(@RequestParam(value = "cameraId", required = false) Long cameraId,
                                                             @RequestParam(value = "space", required = false) Long space) {
        log.info("scene服务调用:updateCameraDetailByCameraIdAndSpace,参数：cameraId:{},space:{},",cameraId,space);
        CameraDetail detail = cameraDetailService.updateCameraDetailByCameraIdAndSpace(cameraId,space);
        log.info("scene服务调用:updateCameraDetailByCameraIdAndSpace,返回:{}",detail);
        return detail;
    }

    @PostMapping("/getCameraBySnCode")
    public Camera getCameraBySnCode(@RequestParam(value = "snCode", required = false) String snCode) {
        log.info("scene服务调用:getCameraBySnCode,参数：snCode:{},",snCode);
        Camera detail = cameraService.getBySnCode(snCode);
        log.info("scene服务调用:getCameraBySnCode,返回:{}",detail);
        return detail;
    }

    @PostMapping("/getByChildNameAndChildPassword")
    public Camera getByChildNameAndChildPassword(@RequestParam(value = "appUserName") String appUserName,
                                                  @RequestParam(value = "appPassword") String appPassword) {
        log.info("scene服务调用:getCameraBySnCode,参数：appUserName:{},appPassword:{}" ,appUserName, appPassword);
        Camera camera = cameraService.getByChildNameAndChildPassword(appUserName, appPassword);
        log.info("scene服务调用:findByChildNameAndChildPassword,返回:{}",camera);
        return camera;
    }

    @PostMapping("/findByChildNameAndChildPassword")
    public Camera findByChildNameAndChildPassword(@RequestParam(value = "appUserName") String appUserName,
                                                  @RequestParam(value = "appPassword") String appPassword) {
        log.info("scene服务调用:findByChildNameAndChildPassword,参数：appUserName:{},appPassword:{}" ,appUserName, appPassword);
        Camera camera = cameraService.getByChildNameAndChildPassword(appUserName, appPassword);
        log.info("scene服务调用:findByChildNameAndChildPassword,返回:{}",camera);
        return camera;
    }

    @PostMapping("/getCameraById")
    public Camera getCameraById(@RequestParam(value = "cameraId") Long cameraId) {
        log.info("scene服务调用:getCameraById,参数：cameraId:{}" ,cameraId);
        Camera camera = cameraService.getAvailableById(cameraId);
        log.info("scene服务调用:getCameraById,返回:{}",camera);
        return camera;
    }

    @PostMapping("/getCameraLikeSnCode")
    List<Camera> getCameraLikeSnCode(@RequestParam(value = "searchKey")String searchKey){
        log.info("scene服务调用:getCameraLikeSnCode,参数：searchKey:{}" ,searchKey);
        List<Camera> cameraList = cameraService.getCameraLikeSnCode(searchKey);
        log.info("scene服务调用:getCameraLikeSnCode,返回:{}",cameraList);
        return cameraList;
    }

    @PostMapping("/test")
    public String test() {
        log.info("scene服务调用:test");
        String test = null;
        test.equals("123");
        log.info("scene服务调用:test");
        return "success";
    }

}

