package com.czg.controller.user;

import com.czg.account.dto.shopinfo.ShopInfoByCodeDTO;
import com.czg.account.dto.shopinfo.ShopInfoDetailDTO;
import com.czg.account.dto.shopinfo.ShopInfoSubVO;
import com.czg.account.entity.ShopTable;
import com.czg.account.service.ShopInfoService;
import com.czg.account.service.ShopTableService;
import com.czg.resp.CzgResult;
import com.czg.sa.StpKit;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import jakarta.annotation.Resource;
import jakarta.validation.constraints.NotEmpty;
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 Administrator
 */
@RestController
@RequestMapping("/user/shopInfo")
public class UShopInfoController {
    @Resource
    private ShopInfoService shopInfoService;
    @Resource
    private ShopTableService shopTableService;

    /**
     * 桌码换取详细店铺信息
     * @return 店铺信息
     */
    @GetMapping
    public CzgResult<ShopInfoByCodeDTO> getByCode(@RequestParam @NotEmpty String tableCode, String lat, String lng) {
        return CzgResult.success(shopInfoService.getByCode(tableCode, lat, lng, true));
    }

    /**
     * 桌码获取详细台桌信息
     * @return 台桌信息
     */
    @GetMapping("/tableInfo")
    public CzgResult<ShopTable> getTableInfo(@RequestParam String tableCode) {
        return CzgResult.success(shopTableService.getOne(new QueryWrapper().eq(ShopTable::getTableCode, tableCode)));
    }

    /**
     * 获取店铺详细信息
     * @return 店铺信息
     */
    @GetMapping("/detail")
    public CzgResult<ShopInfoDetailDTO> get(Long shopId) {
        return CzgResult.success(shopInfoService.getDetail(shopId == null ? StpKit.USER.getShopId() : shopId));
    }

    /**
     * 预约店铺列表,对应预约到店
     * @param lng 精度
     * @param lat 维度
     * @param distance 单位m
     * @return 列表
     */
    @GetMapping("/subList")
    public CzgResult<Page<ShopInfoSubVO>> subList(@RequestParam String lng, @RequestParam String lat, @RequestParam float distance) {
        return CzgResult.success(shopInfoService.getSubList(lat, lng, distance));
    }
}
