package com.m2pool.lease.controller;


import com.m2pool.lease.annotation.Decrypt;
import com.m2pool.lease.dto.*;
import com.m2pool.lease.service.LeaseProductService;
import com.m2pool.lease.service.LeaseUserOwnedProductService;
import com.m2pool.lease.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
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 javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 商品表 前端控制器
 * </p>
 *
 * @author yyb
 * @since 2025-07-23
 */
@Api(tags = "商品控制器")
@RestController
@RequestMapping("/product")
public class LeaseProductController {
    @Autowired
    private LeaseProductService leaseProductService;


    @Resource
    private LeaseUserOwnedProductService leaseUserOwnedProductService;
    @ApiOperation("查询商品列表(不包含商品对应的售卖机器详情列表)")
    @PostMapping("/getList")
    public PageResult<ProductDto> getProductList(@RequestBody(required = false) ProductPageVo productPageVo) {
        if (productPageVo == null){
            productPageVo = new ProductPageVo();
        }
        return leaseProductService.getProductList(productPageVo);
    }


    @ApiOperation("根据商品id查询单个商品详情信息")
    @PostMapping("/getMachineInfoById")
    public Result<ProductDto> getMachineInfoById(@RequestBody BaseVo baseVo) {
        return leaseProductService.getMachineInfoById(baseVo);
    }



    @ApiOperation("查询单个商品详情(包含商品对应的售卖机器详情列表)")
    @PostMapping("/getMachineInfo")
    public PageResult<ProductMachineDto> getProductMachineInfo(@RequestBody ProductMachineVo productMachineVo) {
        return  leaseProductService.getProductMachineInfo(productMachineVo);
    }

    @ApiOperation("单个商品矿机列表页面---获取支付方式")
    @PostMapping("/getPayTypes")
    public Result<List<PayConfigDto>> getPayTypes() {
        return  leaseProductService.getPayTypes();
    }



    @ApiOperation("新增商品(不包含商品对应的售卖机器)")
    @PostMapping("/add")
    public Result<String> addProduct(@RequestBody ProductURDVo productURDVo) {
        return leaseProductService.addProduct(productURDVo);
    }

    @ApiOperation("编辑商品 + 商品上下架(不包含商品对应的售卖机器)")
    @PostMapping("/update")
    public Result<String> updateProduct(@RequestBody ProductURDVo productURDVo) {
        return leaseProductService.updateProduct(productURDVo);
    }

    @ApiOperation("删除商品(包含商品对应的售卖机器)")
    @PostMapping("/delete")
    public Result<String> deleteProduct(@RequestBody BaseVo baseVo) {
        return leaseProductService.deleteProduct(baseVo.getId());
    }


    @ApiOperation("用户查询当前自身已购商品列表")
    @PostMapping("/getOwnedList")
    public PageResult<UserOwnedProductDto> getOwnedList(@RequestBody(required = false) UserOwnedProductVo userOwnedProductVo) {
        if (userOwnedProductVo == null){
            userOwnedProductVo = new UserOwnedProductVo();
        }
        return leaseUserOwnedProductService.getOwnedList(userOwnedProductVo);
    }


    @ApiOperation("根据id查询当前自身已购商品详情")
    @PostMapping("/getOwnedById")
    public Result<UserOwnedProductDto> getOwnedById(@RequestBody BaseVo baseVo) {
        return leaseUserOwnedProductService.getOwnedById(baseVo);
    }


    @ApiOperation("查询用户店铺支持的支付方式")
    @PostMapping("/getSupportPayType")
    public Result<List<PayTypeDto>> getSupportPayType() {
        return leaseProductService.getSupportPayType();
    }


    //TODO 2025-11-21 查询店铺的矿机列表，不存在商品了

    @ApiOperation("获取店铺商品列表用于新增绑定店铺钱包")
    @PostMapping("/getProductListForShopWalletConfig")
    public Result<List<ProductForWalletConfigDto>> getProductListForShopWalletConfig() {
        return leaseProductService.getProductListForShopWalletConfig();
    }

    //TODO 2025-11-21 修改这些矿机的价格，并且绑定新钱包

    @ApiOperation("新增绑定店铺钱包并设置店铺下面每个矿机该钱包币种的售价 + 钱包绑定")
    @PostMapping("/updateProductListForShopWalletConfig")
    @Decrypt
    public Result<String> updateProductListForShopWalletConfig(@RequestBody ProductMachineForWalletConfigVo productMachineForWalletConfigVo) {
        return leaseProductService.updateProductListForShopWalletConfig(productMachineForWalletConfigVo);
    }
}

