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.gift.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 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;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author admin
 */
@Slf4j
@RestController
@RequestMapping("/wx/gift/")
public class WxGiftController {
    @Resource
    private IPlayGiftInfoService giftInfoService;

    /**
     * 顾客查询礼物列表
     *
     * @return 礼物列表
     */
    @GetMapping("/listByAll")
    public R customListByAll() {
        return R.ok(ConvertUtil.entityToVoList(giftInfoService.listByAll(),PlayGiftInfoDto.class));
    }


    /**
     * 顾客查询礼物列表
     *
     * @param obtained 店员获得礼物状态,[0:未获得,1:已获得]
     * @return 礼物列表
     */
    @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参数异常");
        }
        List<PlayClerkGiftReturnVo> list = giftInfoService.clerkListByAll(ThreadLocalRequestDetail.getClerkUserInfo().getId(), obtained);
        return R.ok(list);
    }


    /**
     * 顾客获取礼物图鉴信息
     *
     * @param vo 顾客获得礼物查询对象
     * @return 礼物列表
     */
    @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参数异常");
        }
        List<PlayClerkGiftReturnVo> list = giftInfoService.customListByAll(ThreadLocalRequestDetail.getCustomUserInfo().getId(), obtained);
        return R.ok(list);
    }


}
