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.HotelDishCategory;
import com.jeeplus.hotelorder.dish.service.HotelDishCategoryService;
import com.jeeplus.hotelorder.dish.service.dto.HotelDishCategoryDTO;
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;

@Api(tags = "菜品分类管理")
@RestController
@RequestMapping(value = "/dishCategory")
public class HotelDishCategoryController {

    @Resource
    private HotelDishCategoryService hotelDishCategoryService;

    /**
     * 分页查询分类(带菜品数量)
     * @param page 分页参数
     * @return
     */
    @ApiOperation(value = "分页查询分类(带菜品数量)")
    @GetMapping("page")
    public ResponseEntity<IPage<HotelDishCategoryDTO>> page(Page<HotelDishCategoryDTO> page) {
        Page<HotelDishCategory> entityPage = new Page<>(page.getCurrent(), page.getSize());
        IPage<HotelDishCategoryDTO> result = hotelDishCategoryService.findPage(entityPage);
        return ResponseEntity.ok(result);
    }

    /**
     * 查询所有启用的分类
     * @return
     */
    @ApiOperation(value = "查询所有启用的分类")
    @GetMapping("all")
    public ResponseEntity<List<HotelDishCategoryDTO>> all() {
        List<HotelDishCategoryDTO> list = hotelDishCategoryService.findAll();
        return ResponseEntity.ok(list);
    }

    /**
     * 新增/编辑分类
     * @param dto 分类信息
     * @return
     */
    @ApiOperation(value = "新增/编辑分类")
    @PostMapping("save")
    public ResponseEntity<String> save(@RequestBody HotelDishCategoryDTO dto) {
        String result = hotelDishCategoryService.save(dto);
        return ResponseEntity.ok(result);
    }

    /**
     * 切换分类状态(启用/禁用)
     * @param id 分类ID
     * @return
     */
    @ApiOperation(value = "切换分类状态(启用/禁用)")
    @PostMapping("toggleStatus/{id}")
    public ResponseEntity<String> toggleStatus(@PathVariable String id) {
        String result = hotelDishCategoryService.toggleStatus(id);
        return ResponseEntity.ok(result);
    }

    /**
     * 删除分类
     * @param id 分类ID
     * @return
     */
    @ApiOperation(value = "删除分类")
    @PostMapping("delete/{id}")
    public ResponseEntity<String> delete(@PathVariable String id) {
        String result = hotelDishCategoryService.delete(id);
        return ResponseEntity.ok(result);
    }
}
