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


import com.liquidnet.service.ResponseDto;
import com.liquidnet.service.kylin.dto.param.TicketCreateParam;
import com.liquidnet.service.kylin.dto.vo.partner.TicketCreatePartnerVo;
import com.liquidnet.service.kylin.service.impl.partner.KylinTicketsPartnerServiceImpl;
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.*;

/**
 * <p>
 * 票 前端控制器
 * </p>
 *
 * @author liquidnet
 * @since 2021-05-06
 */
@Api(tags = "第三方-票")
@RestController
@RequestMapping("partner/ticket")
public class KylinTicketsPartnerController {

    @Autowired
    private KylinTicketsPartnerServiceImpl ticketsPartnerService;

    @PostMapping(value = "")
    @ApiOperation(value = "创建票务")
    @ApiResponse(response = TicketCreatePartnerVo.class, code = 200, message = "接口返回对象参数")
    public ResponseDto<TicketCreatePartnerVo> createTicket(@RequestBody TicketCreateParam ticketCreateParam) {
        TicketCreatePartnerVo result = null;
        result = ticketsPartnerService.createTicket(ticketCreateParam);
        if (null == result) {
            return ResponseDto.failure("创建票务失败");
        } else {
            return ResponseDto.success(result);
        }
    }

    @PutMapping(value = "")
    @ApiOperation(value = "修改票务")
    @ApiResponse(response = TicketCreatePartnerVo.class, code = 200, message = "接口返回对象参数")
    public ResponseDto<TicketCreatePartnerVo> updateTicket(@RequestBody TicketCreateParam ticketCreateParam) {
        TicketCreatePartnerVo result = null;
        result = ticketsPartnerService.updateTicket(ticketCreateParam);
        if (null == result) {
            return ResponseDto.failure("修改票务失败");
        } else {
            return ResponseDto.success(result);
        }
    }

    @DeleteMapping(value = "")
    @ApiOperation(value = "删除票务")
    @ApiResponse( code = 200, message = "接口返回对象参数")
    public ResponseDto<String> deleteTicket(@RequestParam("ticketsId") String ticketsId) {
        boolean result = ticketsPartnerService.deleteTicket(ticketsId);
        if (!result) {
            return ResponseDto.failure("删除票务失败");
        } else {
            return ResponseDto.success("删除成功");
        }
    }

    @PostMapping(value = "/copy")
    @ApiOperation(value = "复制票务")
    @ApiResponse(response = TicketCreatePartnerVo.class, code = 200, message = "接口返回对象参数")
    public ResponseDto<TicketCreatePartnerVo> copyTicket(@RequestParam("ticketsId") String ticketsId) {
        TicketCreatePartnerVo result = null;
        result = ticketsPartnerService.copyTicket(ticketsId);
        if (null == result) {
            return ResponseDto.failure("复制票务失败");
        } else {
            return ResponseDto.success(result);
        }
    }

    @GetMapping(value = "/details")
    @ApiOperation(value = "获取票务详情")
    @ApiResponse(response = TicketCreatePartnerVo.class, code = 200, message = "接口返回对象参数")
    public ResponseDto<TicketCreatePartnerVo> getTicketsMongo(@RequestParam("ticketsId") String ticketsId) {
        TicketCreatePartnerVo result = null;
        result = ticketsPartnerService.getTicketsMongo(ticketsId);
        if (null == result) {
            return ResponseDto.failure("查询票务信息失败");
        } else {
            return ResponseDto.success(result);
        }
    }
}
