package com.jeesharp.business.modules.food.controller;

import com.jeesharp.business.modules.food.application.FoodMealMenuApplicationService;
import com.jeesharp.business.modules.food.dto.FoodMealMenuBatchSaveDTO;
import com.jeesharp.business.modules.food.dto.FoodMealMenuCopyDTO;
import com.jeesharp.business.modules.food.dto.FoodMealMenuItemStatusUpdateDTO;
import com.jeesharp.business.modules.food.dto.FoodMealMenuSaveDTO;
import com.jeesharp.business.modules.food.entity.FoodMealMenu;
import com.jeesharp.business.modules.food.vo.FoodMealMenuBatchSaveResultVO;
import com.jeesharp.business.modules.food.vo.FoodMealMenuCopyResultVO;
import com.jeesharp.business.modules.food.vo.FoodMealMenuInfoVO;
import com.jeesharp.business.modules.food.vo.FoodMealMenuListVO;
import com.jeesharp.business.modules.food.vo.FoodMealMenuQueryVO;
import com.jeesharp.framework.pojo.AjaxResult;
import com.jeesharp.framework.pojo.Page;
import com.jeesharp.framework.pojo.query.PageRespVO;
import com.jeesharp.framework.web.controller.BaseController;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "${jeesharp.web.adminPath}/food/mealMenu/v1")
@Tag(name = "订餐菜单发布管理")
@AllArgsConstructor
public class FoodMealMenuController extends BaseController {

    private final FoodMealMenuApplicationService foodMealMenuApplicationService;

    @Operation(summary = "获取详情")
    @PreAuthorize("@ss.hasPermission('manager:business:food:mealMenu:info')")
    @GetMapping("info")
    public AjaxResult<FoodMealMenuInfoVO> info(@RequestParam("id") String id) {
        return AjaxResult.okData(foodMealMenuApplicationService.get(id));
    }

    @Operation(summary = "获取列表（分页）")
    @PreAuthorize("@ss.hasPermission('manager:business:food:mealMenu:list')")
    @PostMapping("list")
    public AjaxResult<PageRespVO<FoodMealMenuListVO>> list(@RequestBody FoodMealMenuQueryVO query) {
        return AjaxResult.okData(foodMealMenuApplicationService.findPage(new Page<FoodMealMenu>(query), query));
    }

    @Operation(summary = "保存")
    @PreAuthorize("@ss.hasPermission('manager:business:food:mealMenu:save') or @ss.hasPermission('manager:business:food:mealMenu:create') or @ss.hasPermission('manager:business:food:mealMenu:update')")
    @PostMapping("save")
    public AjaxResult<Void> save(@RequestBody @Valid FoodMealMenuSaveDTO dto) {
        foodMealMenuApplicationService.save(dto);
        return AjaxResult.ok("保存成功");
    }

    @Operation(summary = "批量配置")
    @PreAuthorize("@ss.hasPermission('manager:business:food:mealMenu:save') or @ss.hasPermission('manager:business:food:mealMenu:create') or @ss.hasPermission('manager:business:food:mealMenu:update')")
    @PostMapping("batchSave")
    public AjaxResult<FoodMealMenuBatchSaveResultVO> batchSave(@RequestBody @Valid FoodMealMenuBatchSaveDTO dto) {
        return AjaxResult.okData(foodMealMenuApplicationService.batchSave(dto));
    }

    @Operation(summary = "复制菜单")
    @PreAuthorize("@ss.hasPermission('manager:business:food:mealMenu:save') or @ss.hasPermission('manager:business:food:mealMenu:create') or @ss.hasPermission('manager:business:food:mealMenu:update')")
    @PostMapping("copy")
    public AjaxResult<FoodMealMenuCopyResultVO> copy(@RequestBody @Valid FoodMealMenuCopyDTO dto) {
        return AjaxResult.okData(foodMealMenuApplicationService.copy(dto));
    }

    @Operation(summary = "发布")
    @PreAuthorize("@ss.hasPermission('manager:business:food:mealMenu:publish')")
    @GetMapping("publish")
    public AjaxResult<Void> publish(@RequestParam("id") String id) {
        foodMealMenuApplicationService.publish(id);
        return AjaxResult.ok("发布成功");
    }

    @Operation(summary = "下线")
    @PreAuthorize("@ss.hasPermission('manager:business:food:mealMenu:offline')")
    @GetMapping("offline")
    public AjaxResult<Void> offline(@RequestParam("id") String id) {
        foodMealMenuApplicationService.offline(id);
        return AjaxResult.ok("下线成功");
    }

    @Operation(summary = "删除")
    @PreAuthorize("@ss.hasPermission('manager:business:food:mealMenu:delete')")
    @GetMapping("delete")
    public AjaxResult<Void> delete(@RequestParam("ids") String ids) {
        foodMealMenuApplicationService.delete(ids);
        return AjaxResult.ok("删除成功");
    }
}
