package com.liquidnet.service.kylin.controller.partner;

import com.github.pagehelper.PageInfo;
import com.liquidnet.service.ResponseDto;
import com.liquidnet.service.kylin.dao.PerformancePartnerListDao;
import com.liquidnet.service.kylin.dto.param.*;
import com.liquidnet.service.kylin.dto.vo.partner.PerformancePartnerVo;
import com.liquidnet.service.kylin.service.impl.partner.KylinPerformancesPartnerServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@Api(tags = "第三方-演出")
@RestController
@RequestMapping("partner/performance")
public class PerformancePartnerController {

    @Autowired
    private KylinPerformancesPartnerServiceImpl performancesPartnerService;

    @PostMapping(value = "list")
    @ApiOperation(value = "演出列表")
    @ApiResponse(code = 200, message = "接口返回对象参数")
    public ResponseDto<PageInfo<PerformancePartnerListDao>> getList(@RequestBody PerformancePartnerListParam performancePartnerListParam) {
        PageInfo<PerformancePartnerListDao> result = null;
        result = performancesPartnerService.getList(performancePartnerListParam);
        if (null == result) {
            return ResponseDto.failure("列表获取失败");
        } else {
            return ResponseDto.success(result);
        }
    }

    @PostMapping(value = "copy")
    @ApiOperation(value = "复制演出")
    @ApiResponse(code = 200, message = "接口返回对象参数")
    public ResponseDto<Map<String,String>> copyPerformance(@RequestParam("performancesId") String performancesId) {
        String result = performancesPartnerService.copyPerformance(performancesId);
        if (null == result) {
            return ResponseDto.failure("复制失败");
        } else {
            Map<String,String> map = new HashMap<>();
            map.put("performancesId",result);
            return ResponseDto.success(map);
        }
    }


    @GetMapping(value = "step1")
    @ApiOperation(value = "获取演出第一步数据")
    @ApiResponse(code = 200, message = "接口返回对象参数")
    public ResponseDto<PerformancePartnerVo> getStep1(@RequestParam("performancesId") String performancesId) {
        PerformancePartnerVo result = performancesPartnerService.getStep1(performancesId);
        if (result == null) {
            return ResponseDto.failure("获取数据失败");
        } else {
            return ResponseDto.success(result);
        }
    }

    @PostMapping(value = "step1")
    @ApiOperation(value = "操作演出第一步")
    @ApiResponse(code = 200, message = "接口返回对象参数")
    public ResponseDto<Map<String,String>> Step1(@RequestBody PerformanceStep1Param performanceStep1Param) {
        String result = performancesPartnerService.step1(performanceStep1Param);
        if (result.isEmpty()) {
            return ResponseDto.failure("操作失败");
        } else {
            Map<String,String> map = new HashMap<>();
            map.put("performancesId",result);
            return ResponseDto.success(map);
        }
    }


    @PostMapping(value = "step2")
    @ApiOperation(value = "操作演出第二步")
    @ApiResponse(code = 200, message = "接口返回对象参数")
    public ResponseDto<String> step2(@RequestBody PerformanceStep2Param performanceStep2Param) {
        boolean result = performancesPartnerService.step2(performanceStep2Param);
        if (!result) {
            return ResponseDto.failure("提交失败");
        } else {
            return ResponseDto.success("提交完成");
        }
    }

    @GetMapping(value = "step2")
    @ApiOperation(value = "获取演出第二步数据")
    @ApiResponse(code = 200, message = "接口返回对象参数")
    public ResponseDto<PerformanceStep2Param> getStep2(@RequestParam("performancesId") String performancesId) {
        PerformanceStep2Param result = performancesPartnerService.getStep2(performancesId);
        if (result == null) {
            return ResponseDto.failure("获取数据失败");
        } else {
            return ResponseDto.success(result);
        }
    }

    @PostMapping(value = "online")
    @ApiOperation(value = "演出上线")
    @ApiResponse(code = 200, message = "接口返回对象参数")
    public ResponseDto<String> onLinePerformance(@RequestParam("performancesId") String performancesId) {
        boolean result = performancesPartnerService.onLinePerformance(performancesId);
        if (result) {
            return ResponseDto.success("上架成功");
        } else {
            return ResponseDto.failure("上架失败");
        }
    }

    @PostMapping(value = "outline")
    @ApiOperation(value = "演出下线")
    @ApiResponse(code = 200, message = "接口返回对象参数")
    public ResponseDto<String> outLinePerformance(@RequestParam("performancesId") String performancesId) {
        boolean result = performancesPartnerService.outLinePerformance(performancesId);
        if (result) {
            return ResponseDto.success("下架成功");
        } else {
            return ResponseDto.failure("下架失败");
        }
    }
}
