package com.corewing.app.modules.app;

import cn.dev33.satoken.stp.StpUtil;
import com.corewing.app.common.Result;
import com.corewing.app.common.annotation.CommonLog;
import com.corewing.app.dto.uploadReplaySessionRequest;
import com.corewing.app.entity.ReplaySession;
import com.corewing.app.service.ReplaySessionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "飞行记录接口")
@RestController
@RequestMapping("/replay-session")
public class AppReplaySessionController {

    @Resource
    private ReplaySessionService replaySessionService;

    /**
     * 获取飞行记录
     * @return
     */
    @CommonLog("获取当前用户飞行记录")
    @ApiOperation("获取当前用户飞行记录")
    @GetMapping("/getReplayList")
    public Result<List<ReplaySession>> getReplayList() {
        return Result.success(replaySessionService.getReplayList(StpUtil.getLoginId()));
    }

    /**
     * 上传飞行记录
     * @param uploadReplaySessionRequests
     * @return
     */
    @CommonLog("上传飞行记录")
    @ApiOperation("上传飞行记录")
    @PostMapping("/uploadReplaySession")
    public Result<Boolean> uploadReplaySession(@RequestBody List<uploadReplaySessionRequest> uploadReplaySessionRequests) {
        return Result.isBool(replaySessionService.uploadReplaySession(uploadReplaySessionRequests));
    }

    /**
     * 根据同步id删除数据
     * @param syncId
     * @return
     */
    @CommonLog("根据同步id删除飞行记录")
    @ApiOperation("根据同步id删除飞行记录")
    @DeleteMapping("/deleteReplaySession/{syncId}")
    public Result<Boolean> deleteReplaySession(@PathVariable String syncId) {
        return Result.isBool(replaySessionService.deleteReplaySession(syncId));
    }

}
