package com.m2pool.lease.controller;


import com.m2pool.common.security.annotation.RequiresLogin;
import com.m2pool.lease.annotation.Decrypt;
import com.m2pool.lease.annotation.LoginRequired;
import com.m2pool.lease.dto.OrderInfoDto;
import com.m2pool.lease.dto.PageResult;
import com.m2pool.lease.dto.PaymentRecordDto;
import com.m2pool.lease.dto.Result;
import com.m2pool.lease.service.LeaseOrderInfoService;
import com.m2pool.lease.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

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

/**
 * <p>
 * 订单表 前端控制器
 * </p>
 *
 * @author yyb
 * @since 2025-07-23
 */
@Api(tags = "订单控制器")
@LoginRequired
@RestController
@RequestMapping("/order/info")
public class LeaseOrderInfoController {


    @Resource
    private LeaseOrderInfoService leaseOrderInfoService;

    @ApiOperation("创建订单及订单详情 + 支付订单(返回二维码内容)")
    @PostMapping("/addOrders")
    @Decrypt
    public Result<String> addOrders(@RequestBody OrderAndCodeVo orderAndCodeVo) {
        return leaseOrderInfoService.addOrders(orderAndCodeVo);
    }

    @ApiOperation("订单支付超时--再次购买功能")
    @PostMapping("/buyAgain")
    @Deprecated
    public Result<List<PaymentRecordDto>> buyAgain(@RequestBody List<OrderInfoVo> orderInfoVoList) {
        return leaseOrderInfoService.buyAgain(orderInfoVoList);
    }

    @ApiOperation("查询订单列表(买家)")
    @PostMapping("/getOrdersByStatus")
    public PageResult<OrderInfoDto> getOrdersByStatus(@RequestBody OrderInfoStateVo orderInfoStateVo) {
        return leaseOrderInfoService.getOrdersByStatus(orderInfoStateVo);
    }


    @ApiOperation("卖家已售出订单列表(卖家)")
    @PostMapping("/getOrdersByStatusForSeller")
    public PageResult<OrderInfoDto> getOrdersByStatusForSeller(@RequestBody OrderInfoStateVo orderInfoStateVo) {
        return leaseOrderInfoService.getOrdersByStatusForSeller(orderInfoStateVo);
    }


    @ApiOperation("根据订单id查询订单信息")
    @PostMapping("/getOrdersByIds")
    public Result<OrderInfoDto> getOrdersByIds(@RequestBody OrderVo orderVo) {
        return leaseOrderInfoService.getOrdersByIds(orderVo);
    }

    @ApiOperation("取消订单（如果有支付订单同时取消）")
    @PostMapping("/cancelOrder")
    public Result<String> cancelOrder(@RequestBody OrderVo orderVo) {
        return leaseOrderInfoService.cancelOrder(orderVo);
    }

    @ApiOperation("生成订单时获取用户选择的支付币种 实时币价")
    @PostMapping("/getCoinPrice")
    public Result<BigDecimal> getCoinPrice(@RequestBody CoinVo coinVo){
         return leaseOrderInfoService.getCoinPrice(coinVo);
    }
}

