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

import com.jeesharp.business.modules.food.application.FoodMealMenuTemplateApplicationService;
import com.jeesharp.business.modules.food.dto.FoodMealMenuTemplateSaveDTO;
import com.jeesharp.business.modules.food.dto.FoodStatusUpdateDTO;
import com.jeesharp.business.modules.food.entity.FoodMealMenuTemplate;
import com.jeesharp.business.modules.food.vo.FoodMealMenuTemplateInfoVO;
import com.jeesharp.business.modules.food.vo.FoodMealMenuTemplateListVO;
import com.jeesharp.business.modules.food.vo.FoodMealMenuTemplateQueryVO;
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.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value = "${jeesharp.web.adminPath}/food/mealMenuTemplate/v1")
@Tag(name = "订餐菜单模板管理")
@AllArgsConstructor
public class FoodMealMenuTemplateController extends BaseController {

    private final FoodMealMenuTemplateApplicationService foodMealMenuTemplateApplicationService;

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

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

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

    @Operation(summary = "更新状态")
    @PreAuthorize("@ss.hasPermission('manager:business:food:mealMenuTemplate:status')")
    @PostMapping("status")
    public AjaxResult<Void> status(@RequestBody @Valid FoodStatusUpdateDTO dto) {
        foodMealMenuTemplateApplicationService.updateStatus(dto.getId(), dto.getStatus());
        return AjaxResult.ok("更新成功");
    }

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