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.MainCompanyApplyBo;
import org.dromara.main.domain.vo.MainCompanyApplyVo;
import org.dromara.main.service.IMainCompanyApplyService;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

@RequiredArgsConstructor
@RestController
@RequestMapping("/main/companyApply")
public class MainCompanyApplyController extends BaseController {

    private final IMainCompanyApplyService mainCompanyApplyService;

    @GetMapping("/list")
    public TableDataInfo<MainCompanyApplyVo> list(MainCompanyApplyBo bo, PageQuery pageQuery) {
        return mainCompanyApplyService.queryPageList(bo, pageQuery);
    }

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

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

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

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