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

import com.jeesharp.business.modules.food.application.FoodCompanyJoinApplicationService;
import com.jeesharp.business.modules.food.dto.FoodCompanyJoinApplyAuditDTO;
import com.jeesharp.business.modules.food.entity.FoodCompanyJoinApply;
import com.jeesharp.business.modules.food.vo.FoodCompanyJoinApplyQueryVO;
import com.jeesharp.business.modules.food.vo.FoodCompanyJoinApplyVO;
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/companyJoinApply/v1")
@Tag(name = "加入审批管理")
@AllArgsConstructor
public class FoodCompanyJoinApplyController extends BaseController {

    private final FoodCompanyJoinApplicationService foodCompanyJoinApplicationService;

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

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

    @Operation(summary = "审批通过")
    @PreAuthorize("@ss.hasPermission('manager:business:food:companyJoinApply:approve')")
    @PostMapping("approve")
    public AjaxResult<Void> approve(@RequestBody @Valid FoodCompanyJoinApplyAuditDTO dto) {
        foodCompanyJoinApplicationService.approve(dto);
        return AjaxResult.ok("审批通过成功");
    }

    @Operation(summary = "审批拒绝")
    @PreAuthorize("@ss.hasPermission('manager:business:food:companyJoinApply:reject')")
    @PostMapping("reject")
    public AjaxResult<Void> reject(@RequestBody @Valid FoodCompanyJoinApplyAuditDTO dto) {
        foodCompanyJoinApplicationService.reject(dto);
        return AjaxResult.ok("审批拒绝成功");
    }

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