package com.czg.controller.user;


import com.czg.account.dto.calltable.CallSubMsgDTO;
import com.czg.account.dto.calltable.CallTableNumDTO;
import com.czg.account.dto.calltable.CallTablePage;
import com.czg.account.dto.calltable.TakeNumberDTO;
import com.czg.account.entity.CallQueue;
import com.czg.account.service.CallTableService;
import com.czg.annotation.SaAdminCheckPermission;
import com.czg.resp.CzgResult;
import com.czg.sa.StpKit;
import com.mybatisflex.core.paginate.Page;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 小程序叫号管理
 * @author Administrator
 */
@RestController
@RequestMapping("/user/callTable")
public class UCallTableController {
    @Resource
    private CallTableService callTableService;
    /**
     * 获取叫号号码
     */
    @PostMapping("takeNumber")
    public CzgResult<CallTableNumDTO> takeNumber(@Validated @RequestBody TakeNumberDTO takeNumberDTO) {
        return CzgResult.success(callTableService.takeNumber(StpKit.USER.getShopId(), takeNumberDTO));
    }

    /**
     * 获取叫号队列
     *
     * @param callTableId 桌型id
     * @param state       状态 -1已取消 0排队中 1叫号中 2已入座 3 已过号
     * @return 分页数据
     */
    @GetMapping("queue")
    public CzgResult<Page<CallQueue>> getQueue(@RequestParam String openId, Long callTableId, Integer state) {
        return CzgResult.success(callTableService.getQueue(StpKit.USER.getShopId(), openId, callTableId, state));
    }

    /**
     * 叫号桌型获取
     *
     * @param callTableId 叫号桌型id
     * @param state       0禁用 1使用
     * @return 分页数据
     */
    @GetMapping
    public CzgResult<CallTablePage> get(Long callTableId, Integer state) {
        return CzgResult.success(callTableService.get(StpKit.USER.getShopId(), callTableId, state));
    }

    /**
     * 根据店铺id和openId获取当前叫号号码
     * @param queueId 队列id
     * @return 状态
     */
    @GetMapping("/queue/detail")
    public CzgResult<?> getStatus(@RequestParam String openId, @RequestParam(required = false) Long queueId) {
        return CzgResult.success(callTableService.getStatus(StpKit.USER.getShopId(), openId, queueId));
    }

    /**
     * 消息订阅
     * @return 是否成功
     */
    @PostMapping("subMsg")
    public CzgResult<Boolean> subMsg(
            @Validated @RequestBody CallSubMsgDTO subMsgDTO
    ) {
        return CzgResult.success(callTableService.subMsg(subMsgDTO));
    }

    /**
     * 取消订阅
     * @param queueId 队列id
     * @param shopId 店铺id
     * @return 是否成功
     */
    @DeleteMapping("/cancel")
    public CzgResult<Boolean> cancel(@RequestParam Long queueId, @RequestParam Long shopId) {
        return CzgResult.success(callTableService.cancel(shopId, queueId));
    }


}
