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

import com.jeesharp.business.modules.food.application.FoodMealServiceAreaApplicationService;
import com.jeesharp.business.modules.food.dto.FoodMealServiceAreaSaveDTO;
import com.jeesharp.business.modules.food.entity.FoodMealServiceArea;
import com.jeesharp.business.modules.food.vo.FoodMealServiceAreaInfoVO;
import com.jeesharp.business.modules.food.vo.FoodMealServiceAreaListVO;
import com.jeesharp.business.modules.food.vo.FoodMealServiceAreaQueryVO;
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/mealServiceArea/v1")
@Tag(name = "订餐服务区域管理")
@AllArgsConstructor
public class FoodMealServiceAreaController extends BaseController {

    private final FoodMealServiceAreaApplicationService foodMealServiceAreaApplicationService;

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

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

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

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