package com.m2pool.lease.controller;


import com.m2pool.lease.annotation.Decrypt;
import com.m2pool.lease.annotation.LoginRequired;
import com.m2pool.lease.dto.PageResult;
import com.m2pool.lease.dto.Result;
import com.m2pool.lease.dto.v2.*;
import com.m2pool.lease.service.LeaseOrderInfoService;
import com.m2pool.lease.vo.BaseVo;
import com.m2pool.lease.vo.OrderAndCodeVo;
import com.m2pool.lease.vo.PageVo;
import com.m2pool.lease.vo.v2.CoinAndAlgorithmVo;
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.util.List;

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

    @Resource
    private LeaseOrderInfoService leaseOrderInfoService;

    @ApiOperation("算法币种选择框：购物车结算获取选中矿机支持的算法和币种列表")
    @PostMapping("/getMachineSupportCoinAndAlgorithm")
    public Result<List<CoinAndAlgorithmListDto>> getMachineSupportCoinAndAlgorithm(@RequestBody List<BaseVo> machineIds) {
        return leaseOrderInfoService.getMachineSupportCoinAndAlgorithm(machineIds);
    }

    @ApiOperation("矿池选择框:根据矿机id 获取当前矿机支持的矿池币种信息")
    @PostMapping("/getMachineSupportPool")
    public Result<List<MiningInfoDto>> getMachineSupportPool(@RequestBody CoinAndAlgorithmVo coinAndAlgorithmVo) {
        return leaseOrderInfoService.getMachineSupportPool(coinAndAlgorithmVo);
    }

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


    @ApiOperation("买家:已购矿机列表")
    @PostMapping("/getPurchasedItems")
    public PageResult<PurchasedMachineListDto> getPurchasedItems(@RequestBody(required = false) PageVo pageVo) {
        if (pageVo == null){
            pageVo = new PageVo();
        }
        return leaseOrderInfoService.getPurchasedItems(pageVo);
    }



    @ApiOperation("买家:根据id查询已购矿机详情")
    @PostMapping("/getPurchasedInfo")
    public Result<MiningConfigInfoDto> getPurchasedInfo(@RequestBody BaseVo baseVo) {
        return leaseOrderInfoService.getPurchasedInfo(baseVo);
    }
}

