package com.starry.admin.modules.weichat.controller;

import cn.hutool.core.util.StrUtil;
import com.starry.admin.common.aspect.ClerkUserLogin;
import com.starry.admin.common.aspect.CustomUserLogin;
import com.starry.admin.common.conf.ThreadLocalRequestDetail;
import com.starry.admin.common.exception.CustomException;
import com.starry.admin.modules.clerk.module.entity.PlayClerkUserInfoEntity;
import com.starry.admin.modules.custom.module.entity.PlayCustomUserInfoEntity;
import com.starry.admin.modules.shop.service.IPlayGiftInfoService;
import com.starry.admin.modules.weichat.entity.PlayGiftInfoDto;
import com.starry.admin.modules.weichat.entity.gift.PlayClerkGiftReturnVo;
import com.starry.common.result.R;
import com.starry.common.utils.ConvertUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import java.util.List;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author admin
 */
@Api(tags = "微信礼物接口", description = "微信端礼物相关接口")
@Slf4j
@RestController
@RequestMapping("/wx/gift/")
public class WxGiftController {
    @Resource
    private IPlayGiftInfoService giftInfoService;

    /**
     * 顾客查询礼物列表
     *
     * @return 礼物列表
     */
    @ApiOperation(value = "查询所有礼物", notes = "查询系统中所有礼物列表")
    @ApiResponses({
            @ApiResponse(code = 200, message = "操作成功", response = PlayGiftInfoDto.class, responseContainer = "List")})
    @GetMapping("/listByAll")
    public R customListByAll() {
        return R.ok(ConvertUtil.entityToVoList(giftInfoService.listByAll(), PlayGiftInfoDto.class));
    }

    /**
     * 顾客查询礼物列表
     *
     * @param obtained
     *            店员获得礼物状态,[0:未获得,1:已获得]
     * @return 礼物列表
     */
    @ApiOperation(value = "店员查询礼物", notes = "根据获得状态查询店员礼物列表")
    @ApiImplicitParam(name = "obtained", value = "获得状态[0:未获得,1:已获得]", required = true, dataType = "String", paramType = "query", allowableValues = "0,1")
    @ApiResponses({
            @ApiResponse(code = 200, message = "操作成功", response = PlayClerkGiftReturnVo.class, responseContainer = "List"),
            @ApiResponse(code = 500, message = "obtained参数异常")})
    @ClerkUserLogin
    @GetMapping("/clerk/listByAll")
    public R clerkListByAll(@RequestParam("obtained") String obtained) {
        if (StrUtil.isBlankIfStr(obtained)) {
            throw new CustomException("obtained参数异常");
        }
        if (!"0".equals(obtained) && !"1".equals(obtained)) {
            throw new CustomException("obtained参数异常");
        }
        PlayClerkUserInfoEntity clerk = ThreadLocalRequestDetail.getClerkUserInfo();
        List<PlayClerkGiftReturnVo> list = giftInfoService
                .clerkListByAll(clerk.getTenantId(), clerk.getId(), obtained);
        return R.ok(list);
    }

    /**
     * 顾客获取礼物图鉴信息
     *
     * @param vo
     *            顾客获得礼物查询对象
     * @return 礼物列表
     */
    @ApiOperation(value = "顾客查询礼物", notes = "根据获得状态查询顾客礼物列表")
    @ApiImplicitParam(name = "obtained", value = "获得状态[0:未获得,1:已获得]", required = true, dataType = "String", paramType = "query", allowableValues = "0,1")
    @ApiResponses({
            @ApiResponse(code = 200, message = "操作成功", response = PlayClerkGiftReturnVo.class, responseContainer = "List"),
            @ApiResponse(code = 500, message = "obtained参数异常")})
    @CustomUserLogin
    @GetMapping("/custom/listByAll")
    public R customListByAll(@RequestParam("obtained") String obtained) {
        if (StrUtil.isBlankIfStr(obtained)) {
            throw new CustomException("obtained参数异常");
        }
        if (!"0".equals(obtained) && !"1".equals(obtained)) {
            throw new CustomException("obtained参数异常");
        }
        PlayCustomUserInfoEntity custom = ThreadLocalRequestDetail.getCustomUserInfo();
        List<PlayClerkGiftReturnVo> list = giftInfoService
                .customListByAll(custom.getTenantId(), custom.getId(), obtained);
        return R.ok(list);
    }

}
