package org.dromara.main.controller;

import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.web.core.BaseController;
import org.dromara.main.domain.bo.MainAuditBo;
import org.dromara.main.domain.vo.MainAuditVo;
import org.dromara.main.service.IMainAuditService;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

@RequiredArgsConstructor
@RestController
@RequestMapping("/main/audit")
public class MainAuditController extends BaseController {

    private final IMainAuditService mainAuditService;

    /**
     * 查询审核列表（包含企业/岗位详情）
     */
    @GetMapping("/list")
    public TableDataInfo<MainAuditVo> list(MainAuditBo bo, PageQuery pageQuery) {
        return mainAuditService.queryDetailPageList(bo, pageQuery);
    }

    /**
     * 获取审核详细信息（包含企业/岗位详情）
     */
    @GetMapping("/{id}")
    public R<MainAuditVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable Long id) {
        return R.ok(mainAuditService.queryDetailById(id));
    }

    /**
     * 新增审核
     */
    @PostMapping("/add")
    public R<Void> add(@RequestBody MainAuditBo bo) {
        return toAjax(mainAuditService.insertByBo(bo));
    }

    /**
     * 修改审核
     */
    @PutMapping("/edit")
    public R<Void> edit(@RequestBody MainAuditBo bo) {
        return toAjax(mainAuditService.updateByBo(bo));
    }

    /**
     * 删除审核
     */
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable Long[] ids) {
        return toAjax(mainAuditService.deleteWithValidByIds(Arrays.asList(ids), true));
    }

    /**
     * 审核通过
     */
    @PutMapping("/pass/{id}")
    public R<Void> auditPass(@PathVariable Long id, @RequestParam(required = false) String remark) {
        return toAjax(mainAuditService.auditPass(id, remark));
    }

    /**
     * 审核驳回
     */
    @PutMapping("/reject/{id}")
    public R<Void> auditReject(@PathVariable Long id, @RequestParam String remark) {
        return toAjax(mainAuditService.auditReject(id, remark));
    }
}
