package com.dji.sample.manage.controller;

import com.dji.sample.manage.model.dto.*;
import com.dji.sample.manage.service.IDevicePayloadService;
import com.dji.sample.manage.service.IDeviceService;
import com.dji.sample.manage.service.IManageDeviceLivestreamUrlService;
import com.dji.sample.media.model.UpstreamMediaFileDTO;
import com.dji.sample.media.service.IFileService;
import com.dji.sample.media.service.IMediaDirService;
import com.dji.sdk.common.HttpResultResponse;
import com.dji.sdk.common.PaginationData;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author sean.zhou
 * @version 0.1
 * @date 2021/11/15
 */
@RestController
@Slf4j
@RequestMapping("${url.manage.prefix}${url.manage.version}/upstream")
public class UpstreamController {

    @Autowired
    private IDeviceService deviceService;


    @Autowired
    private IManageDeviceLivestreamUrlService livestreamUrlService;

    @Autowired
    private IFileService fileService;


    /**
     * 上游系统获取设备列表信息
     * @param searchInfo
     * @param status
     * @return
     */
    @GetMapping("/devicesList")
    public HttpResultResponse<List<UpstreamDeviceDTO>> getDevicesList(String searchInfo,
                                                                      Integer status,
                                                                      String workspaceId) {
        List<UpstreamDeviceDTO> devices = deviceService.selUpstreamDeviceList(searchInfo, status,workspaceId);
        return HttpResultResponse.success(devices);
    }

    /**
     * 上游系统获取图片文件信息
     * @param workspaceName
     * @param startTime
     * @param endTime
     * @return
     */
    @GetMapping("/files")
    public HttpResultResponse<PaginationData<UpstreamMediaFileDTO>> getFilesList(@RequestParam(defaultValue = "1") Long page,
                                                                                @RequestParam(name = "page_size", defaultValue = "10") Long pageSize,
                                                                                String workspaceName,
                                                                                Long startTime,
                                                                                Long endTime,
                                                                                 String workspaceId) {
        PaginationData<UpstreamMediaFileDTO> filesList = fileService.getMediaFilesPagination(workspaceName, startTime,endTime, page, pageSize,workspaceId);
        return HttpResultResponse.success(filesList);
    }

    /**
     * 上游系统获取直播地址
     * @param payload
     * @param deviceSn
     * @return
     */
    @GetMapping("/webRtc")
    public HttpResultResponse<List<UpstreamLivestreamUrlDTO>> getWebRtc(String payload,
                                                                    String deviceSn,
                                                                    String workspaceId) {
        List<UpstreamLivestreamUrlDTO> url = livestreamUrlService.selWebRtc(payload, deviceSn,workspaceId);
        return HttpResultResponse.success(url);
    }

    /**
     * 上游系统获取设备列表详情信息
     * @param searchInfo
     * @param status
     * @return
     */
    @GetMapping("/devicesDetailList")
    public HttpResultResponse<List<UpstreamDeviceDetailDTO>> getDevicesDetailList(String searchInfo,
                                                                                    Integer status,
                                                                                  String workspaceId) {
        List<UpstreamDeviceDetailDTO> devices = deviceService.selUpstreamDeviceDetailList(searchInfo, status,workspaceId);
        return HttpResultResponse.success(devices);
    }

}