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.HotelDishSpecOption;
import com.jeeplus.hotelorder.dish.service.HotelDishSpecOptionService;
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 = "/dishSpecOption")
public class HotelDishSpecOptionController {

    @Resource
    private HotelDishSpecOptionService hotelDishSpecOptionService;

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

    /**
     * 根据规格组ID查询所有选项
     * @param groupId 规格组ID
     * @return 选项列表
     */
    @ApiOperation(value = "根据规格组ID查询选项")
    @GetMapping("findByGroupId")
    public ResponseEntity<List<HotelDishSpecOption>> findByGroupId(@RequestParam("groupId") String groupId) {
        List<HotelDishSpecOption> list = hotelDishSpecOptionService.findByGroupId(groupId);
        return ResponseEntity.ok(list);
    }

    /**
     * 查询规格选项详情
     * @param id 选项ID
     * @return 选项信息
     */
    @ApiOperation(value = "查询规格选项详情")
    @GetMapping("queryById")
    public ResponseEntity<HotelDishSpecOption> queryById(@RequestParam("id") String id) {
        HotelDishSpecOption specOption = hotelDishSpecOptionService.queryById(id);
        return ResponseEntity.ok(specOption);
    }

    /**
     * 新增/编辑规格选项
     * @param specOption 选项信息
     * @return 操作结果
     */
    @ApiOperation(value = "新增/编辑规格选项")
    @PostMapping("save")
    public ResponseEntity<String> save(@RequestBody HotelDishSpecOption specOption) {
        String result = hotelDishSpecOptionService.saveSpecOption(specOption);
        return ResponseEntity.ok(result);
    }

    /**
     * 删除规格选项
     * @param id 选项ID
     * @return 操作结果
     */
    @ApiOperation(value = "删除规格选项")
    @PostMapping("delete/{id}")
    public ResponseEntity<String> delete(@PathVariable String id) {
        hotelDishSpecOptionService.deleteSpecOption(id);
        return ResponseEntity.ok("删除成功");
    }
}
