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

import com.jeesharp.business.modules.food.application.FoodRestaurantApplicationService;
import com.jeesharp.business.modules.food.dto.FoodRestaurantSaveDTO;
import com.jeesharp.business.modules.food.entity.FoodRestaurant;
import com.jeesharp.business.modules.food.vo.FoodRestaurantInfoVO;
import com.jeesharp.business.modules.food.vo.FoodRestaurantListVO;
import com.jeesharp.business.modules.food.vo.FoodRestaurantQueryVO;
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.*;

/**
 * 管理端美食门店主数据接口：门店信息维护与上下架。
 *
 * @author jeesharp
 * @since 2026-06-04
 */
@RestController
@RequestMapping(value = "${jeesharp.web.adminPath}/manager/business/food/restaurant/v1")
@Tag(name = "美食门店管理")
@AllArgsConstructor
public class FoodRestaurantController extends BaseController {

    private static final String SAVE_SUCCESS_MESSAGE = "保存成功";
    private static final String DELETE_SUCCESS_MESSAGE = "删除成功";

    private final FoodRestaurantApplicationService foodRestaurantApplicationService;

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

    @Operation(summary = "获取列表（分页）")
    @PreAuthorize("@ss.hasPermission('manager:business:food:restaurant:list')")
    @PostMapping("list")
    public AjaxResult<PageRespVO<FoodRestaurantListVO>> list(@RequestBody FoodRestaurantQueryVO query) {
        PageRespVO<FoodRestaurantListVO> page = foodRestaurantApplicationService.findPage(new Page<FoodRestaurant>(query), query);
        return AjaxResult.okData(page);
    }

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

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