package com.jeeplus.hotelorder.dish.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jeeplus.hotelorder.dish.domain.HotelDishSpecGroup;
import com.jeeplus.hotelorder.dish.service.HotelDishSpecGroupService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

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

/**
 * 菜品规格组管理Controller
 * @author jeeplus
 */
@Api(tags = "菜品规格组管理")
@RestController
@RequestMapping(value = "/dishSpecGroup")
public class HotelDishSpecGroupController {

    @Resource
    private HotelDishSpecGroupService hotelDishSpecGroupService;

    /**
     * 分页查询规格组
     * @param specGroup 查询条件
     * @param page 分页参数
     * @return 分页结果
     * @throws Exception 查询异常
     */
    @ApiOperation(value = "分页查询规格组")
    @GetMapping("page")
    public ResponseEntity<IPage<HotelDishSpecGroup>> page(HotelDishSpecGroup specGroup, Page<HotelDishSpecGroup> page) throws Exception {
        IPage<HotelDishSpecGroup> result = hotelDishSpecGroupService.findPage(page, specGroup);
        return ResponseEntity.ok(result);
    }

    /**
     * 根据菜品ID查询所有规格组（含选项）
     * @param dishId 菜品ID
     * @return 规格组列表
     */
    @ApiOperation(value = "根据菜品ID查询规格组")
    @GetMapping("findByDishId")
    public ResponseEntity<List<HotelDishSpecGroup>> findByDishId(@RequestParam("dishId") String dishId) {
        List<HotelDishSpecGroup> list = hotelDishSpecGroupService.findByDishId(dishId);
        return ResponseEntity.ok(list);
    }

    /**
     * 查询规格组详情
     * @param id 规格组ID
     * @return 规格组信息
     */
    @ApiOperation(value = "查询规格组详情")
    @GetMapping("queryById")
    public ResponseEntity<HotelDishSpecGroup> queryById(@RequestParam("id") String id) {
        HotelDishSpecGroup specGroup = hotelDishSpecGroupService.queryById(id);
        return ResponseEntity.ok(specGroup);
    }

    /**
     * 新增/编辑规格组
     * @param specGroup 规格组信息
     * @return 操作结果
     */
    @ApiOperation(value = "新增/编辑规格组")
    @PostMapping("save")
    public ResponseEntity<String> save(@RequestBody HotelDishSpecGroup specGroup) {
        String result = hotelDishSpecGroupService.saveSpecGroup(specGroup);
        return ResponseEntity.ok(result);
    }

    /**
     * 删除规格组（含级联删除选项）
     * @param id 规格组ID
     * @return 操作结果
     */
    @ApiOperation(value = "删除规格组")
    @PostMapping("delete/{id}")
    public ResponseEntity<String> delete(@PathVariable String id) {
        hotelDishSpecGroupService.deleteSpecGroup(id);
        return ResponseEntity.ok("删除成功");
    }
}
