package com.czg.controller.kitchen;

import com.czg.annotation.SaAdminCheckPermission;
import com.czg.order.vo.KitchenFoodVO;
import com.czg.order.vo.KitchenTableFoodVO;
import com.czg.order.vo.KitchenTableVO;
import com.czg.resp.CzgResult;
import com.czg.sa.StpKit;
import com.czg.service.order.mapper.KitchenDetailMapper;
import jakarta.annotation.Resource;
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 java.util.List;

/**
 * 后厨：台桌/菜单
 *
 * @author tankaikai
 * @since 2025-03-07 15:25
 */
@RestController
@RequestMapping("/admin/kitchen")
public class TableController {

    @Resource
    private KitchenDetailMapper kitchenDetailMapper;


    /**
     * 按台桌查看
     */
    @GetMapping("getKitchenTable")
    @SaAdminCheckPermission(parentName = "后厨相关", value = "kitchen:table", name = "后厨-按台桌查看")
    public CzgResult<List<KitchenTableVO>> getKitchenTable(@RequestParam(required = false) String tableName, @RequestParam(required = false) Long areaId) {
        Long shopId = StpKit.USER.getShopId();
        List<KitchenTableVO> kitchenTables = kitchenDetailMapper.getKitchenTable(shopId, tableName, areaId);
        return CzgResult.success(kitchenTables);
    }

    /**
     * 按台桌查看 商品内容
     */
    @GetMapping("getKitchenTableFoods")
    @SaAdminCheckPermission(parentName = "后厨相关", value = "kitchen:tableFood", name = "后厨-按台桌查看商品内容")
    public CzgResult<List<KitchenTableFoodVO>> getKitchenTableFoods(@RequestParam(required = false) Long orderId,
                                                                    @RequestParam(required = false) String tableCode,
                                                                    @RequestParam(required = false) Long isNoTable) {
        Long shopId = StpKit.USER.getShopId();
        if (isNoTable != null) {
            tableCode = null;
        }
        List<KitchenTableFoodVO> kitchenFood = kitchenDetailMapper.getKitchenTableFoods(shopId, orderId, tableCode, isNoTable);
        return CzgResult.success(kitchenFood);
    }


    /**
     * 按商品查看
     */
    @GetMapping("getKitchenFood")
    @SaAdminCheckPermission(parentName = "后厨相关", value = "kitchen:table", name = "后厨-按台桌查看")
    public CzgResult<List<KitchenFoodVO>> getKitchenFood(@RequestParam(required = false) String productName, @RequestParam(required = false) Long categoryId) {
        Long shopId = StpKit.USER.getShopId();
        List<KitchenFoodVO> kitchenFood = kitchenDetailMapper.getKitchenFood(shopId, productName, categoryId);
        return CzgResult.success(kitchenFood);
    }
}
