package com.liquidnet.service.goblin.controller;

import com.github.pagehelper.PageInfo;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.goblin.dto.vo.GoblinNftGoodsInfoListVo;
import com.liquidnet.service.goblin.service.IGoblinNftGoodsAppService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@Api(tags = "NFT商品-App")
@RestController
@RequestMapping("/nftGoods")
public class GoblinNftGoodsAppController {

    @Autowired
    IGoblinNftGoodsAppService goblinNftGoodsAppService;

    @GetMapping("list")
    @ApiOperation("获得NFT商品列表")
    @ApiImplicitParams({
            @ApiImplicitParam(type = "query", dataType = "String", name = "page", value = "页码", example = "1"),
    })
    public ResponseDto<PageInfo<GoblinNftGoodsInfoListVo>> getGoodsList(
            @RequestParam(name = "page", defaultValue = "1") Integer page
    ) {
        return goblinNftGoodsAppService.goodsList(page);
    }

    @GetMapping("detail")
    @ApiOperation("获得商品详情")
    @ApiImplicitParams({
            @ApiImplicitParam(type = "query", required = true, dataType = "String", name = "spuId", value = "spuId", example = "1"),
            @ApiImplicitParam(type = "query", required = true, dataType = "String", name = "skuId", value = "skuId", example = "1"),
    })
    public ResponseDto<GoblinNftGoodsInfoListVo> getGoodsDetail(
            @RequestParam("spuId") String spuId,
            @RequestParam("skuId") String skuId
    ) {
        GoblinNftGoodsInfoListVo vo = goblinNftGoodsAppService.goodsDetail(spuId, skuId);
        if (vo == null) {
            return ResponseDto.failure("商品不存在");
        }
        return ResponseDto.success(vo);
    }

    @PostMapping("exchange")
    @ApiOperation("兑换码兑换")
    @ApiImplicitParams({
            @ApiImplicitParam(type = "from", required = true, dataType = "String", name = "code", value = "兑换码", example = "1"),
    })
    public ResponseDto exchange(
            @RequestParam("code") String code
    ) {
        Boolean res = goblinNftGoodsAppService.exchange(code);
        if (res) {
            return ResponseDto.success();
        } else {
            return ResponseDto.failure();
        }
    }

}
