package com.m2pool.lease.controller;


import com.m2pool.lease.annotation.LoginRequired;
import com.m2pool.lease.dto.PageResult;
import com.m2pool.lease.dto.ProductUpdateMachineDto;
import com.m2pool.lease.dto.Result;
import com.m2pool.lease.dto.UserMinerDto;
import com.m2pool.lease.service.LeaseProductMachineService;
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.util.List;
import java.util.Map;

/**
 * <p>
 * 商品表对应的物品机器表 前端控制器
 * </p>
 *
 * @author yyb
 * @since 2025-07-23
 */
@Api(tags = "商品矿机控制器（库存控制器）")
@LoginRequired
@RestController
@RequestMapping("/product/machine")
public class LeaseProductMachineController {


    @Resource
    private LeaseProductMachineService leaseProductMachineService;


    @ApiOperation("根据 登录账户 获取挖矿账户及挖矿币种集合----用于用户为商品添加实际出售机器库存")
    @PostMapping("/getUserMinersList")
    public Result<Map<String, List<UserMinerDto>>> getUserMinersList(@RequestBody UserMinerVo userMinerVo) {
        return leaseProductMachineService.getUserMinersList(userMinerVo);
    }

    @ApiOperation("根据挖矿账户获取对应的 矿机机器编码集合----用于用户为商品添加实际出售机器库存")
    @PostMapping("/getUserMachineList")
    public Result<List<UserMinerDto>> getUserMachineList(@RequestBody UserMinerVo userMinerVo) {
        return leaseProductMachineService.getUserMachineList(userMinerVo);
    }




    @ApiOperation("根据商品id查询商品矿机列表----用于卖方修改矿机信息")
    @PostMapping("/getMachineListForUpdate")
    public PageResult<ProductUpdateMachineDto> getMachineListForUpdate(@RequestBody ProductForUpdateMachineVo productForUpdateMachineVo) {
        return leaseProductMachineService.getMachineListForUpdate(productForUpdateMachineVo);
    }


    @ApiOperation("单个新增或批量新增出售机器")
    @PostMapping("/addSingleOrBatchMachine")
    public Result<String> addSingleOrBatchMachine(@RequestBody ProductMachineParamsVo productMachineParamsVoList) {
        return leaseProductMachineService.addSingleOrBatchMachine(productMachineParamsVoList);
    }

    @ApiOperation("单个/批量 编辑矿机 + 矿机上下架")
    @PostMapping("/updateMachine")
    public Result<String> updateMachine(@RequestBody List<ProductUpdateMachineVo> productUpdateMachineVoList) {
        return leaseProductMachineService.updateMachine(productUpdateMachineVoList);
    }

    @ApiOperation("根据矿机id 删除商品矿机")
    @PostMapping("/delete")
    public Result<String> deleteMachine(@RequestBody BaseVo baseVo) {
        return leaseProductMachineService.deleteMachine(baseVo);
    }


    //@ApiOperation("价格计算器---添加机器到商品中时需要给一个价格")
    //@PostMapping("/calculatePrice")
    //public Result<BigDecimal> calculatePrice(@RequestBody PriceCalculateVo priceCalculateVo) {
    //    return leaseProductMachineService.calculatePrice(priceCalculateVo);
    //}


}

