package cn.iocoder.yudao.module.member.controller.app.diningplates;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.member.controller.admin.diningplates.vo.DiningPlatesRespVO;
import cn.iocoder.yudao.module.member.controller.app.diningplates.vo.AppUserInfo;
import cn.iocoder.yudao.module.member.controller.app.user.vo.AppUserInfoCardVO;
import cn.iocoder.yudao.module.member.dal.dataobject.diningplates.DiningPlatesDO;
import cn.iocoder.yudao.module.member.service.diningplates.DiningPlatesService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

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

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "用户 App - 餐盘")
@RestController
@RequestMapping("/member/dining-plates")
@Validated
public class AppDiningPlatesController {

    @Resource
    private DiningPlatesService diningPlatesService;


    @GetMapping("/list")
    @Operation(summary = "获得餐盘列表")
    public CommonResult<List<DiningPlatesRespVO>> getDiningPlatesPage() {
        List<DiningPlatesDO> pageResult = diningPlatesService.getDiningPlatesList();
        return success(BeanUtils.toBean(pageResult, DiningPlatesRespVO.class));
    }

    @GetMapping("/bindByCard")
    @Operation(summary = "打卡绑定餐盘")
    public CommonResult<AppUserInfoCardVO> bindByCard(String diningPlatesNum,String cardId,Long storeId) {
        return success(diningPlatesService.bind(diningPlatesNum,cardId,storeId));
    }

    @GetMapping("/bindByFace")
    @Operation(summary = "人脸绑定餐盘")
    public CommonResult<AppUserInfoCardVO> bindByFace(String diningPlatesNum, Long faceId,Long storeId) {
        return success(diningPlatesService.bindByFace(diningPlatesNum,faceId,storeId));
    }

    @GetMapping("/checkBind")
    @Operation(summary = "验证餐盘绑定")
    public CommonResult<AppUserInfoCardVO> checkBind(String diningPlatesNum,Long storeId) {
        return success(diningPlatesService.appCheckBind(diningPlatesNum,storeId));
    }

    @GetMapping("/unbind")
    @Operation(summary = "餐盘解绑")
    public CommonResult<String> unbind(String diningPlatesNum,Long storeId) {
        diningPlatesService.unbind(diningPlatesNum,storeId);
        return success(diningPlatesNum);
    }

    @GetMapping("/getUserAndDish")
    @Operation(summary = "根据餐盘号获取当前余额")
    public CommonResult<AppUserInfo> getMoney(String cId, Long dishesId,Long storeId) {
        return success(diningPlatesService.getMoney(cId,dishesId,storeId));
    }

    @GetMapping("/getBind")
    @Operation(summary = "获取绑定餐盘验证")
    public CommonResult<List<String>> getBind() {
        return success(diningPlatesService.getBindDiningPlatesList());
    }

    @GetMapping("/checkBindAndUnBind")
    @Operation(summary = "餐盘解绑")
    public CommonResult<String> checkBindAndUnBind(String diningPlatesNum,Long storeId) {
        Boolean b = diningPlatesService.checkBindAndUnBind(diningPlatesNum, storeId);
        CommonResult<String> result = new CommonResult<>();
        result.setCode(200);
        if (b) {
            result.setMsg("餐盘已解绑");
            result.setData("bind");
        }else {
            result.setData("unbind");
        }
        return result;
    }

}