package org.dromara.main.controller;

import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
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.MainPostCandidateHireBo;
import org.dromara.main.domain.bo.MainPostCandidateQueryBo;
import org.dromara.main.domain.bo.MainPostCandidateStatusBo;
import org.dromara.main.domain.vo.MainPostCandidateVo;
import org.dromara.main.service.IMainPostCandidateService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequiredArgsConstructor
@RestController
@RequestMapping("/main/postCandidate")
public class MainPostCandidateController extends BaseController {

    private final IMainPostCandidateService mainPostCandidateService;

    @GetMapping("/list")
    public TableDataInfo<MainPostCandidateVo> list(MainPostCandidateQueryBo bo, PageQuery pageQuery) {
        return mainPostCandidateService.queryPageList(bo, pageQuery);
    }

    @Log(title = "岗位报名列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(MainPostCandidateQueryBo bo, HttpServletResponse response) {
        List<MainPostCandidateVo> list = mainPostCandidateService.queryList(bo);
        ExcelUtil.exportExcel(list, "岗位报名列表", MainPostCandidateVo.class, response);
    }

    @PostMapping("/hire")
    public R<Void> hire(@RequestBody MainPostCandidateHireBo bo) {
        return toAjax(mainPostCandidateService.hireCandidate(bo));
    }

    @PutMapping("/status")
    public R<Void> updateStatus(@RequestBody MainPostCandidateStatusBo bo) {
        return toAjax(mainPostCandidateService.updateStatus(bo));
    }
}
