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.MainPostApplyBo;
import org.dromara.main.domain.vo.MainPostApplyVo;
import org.dromara.main.service.IMainPostApplyService;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

@RequiredArgsConstructor
@RestController
@RequestMapping("/main/postApply")
public class MainPostApplyController extends BaseController {

    private final IMainPostApplyService mainPostApplyService;

    @GetMapping("/list")
    public TableDataInfo<MainPostApplyVo> list(MainPostApplyBo bo, PageQuery pageQuery) {
        return mainPostApplyService.queryPageList(bo, pageQuery);
    }

    @GetMapping("/{id}")
    public R<MainPostApplyVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable Long id) {
        return R.ok(mainPostApplyService.queryById(id));
    }

    @PostMapping("/add")
    public R<Void> add(@RequestBody MainPostApplyBo bo) {
        return toAjax(mainPostApplyService.insertByBo(bo));
    }

    @PutMapping("/edit")
    public R<Void> edit(@RequestBody MainPostApplyBo bo) {
        return toAjax(mainPostApplyService.updateByBo(bo));
    }

    @PostMapping("/publish/{id}")
    public R<Void> publish(@NotNull(message = "主键不能为空") @PathVariable Long id) {
        return toAjax(mainPostApplyService.publishById(id));
    }

    @PostMapping("/unpublish/{id}")
    public R<Void> unpublish(@NotNull(message = "主键不能为空") @PathVariable Long id) {
        return toAjax(mainPostApplyService.unpublishById(id));
    }

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