package com.ruoyi.web.controller.bgt;

import com.ruoyi.bgt.domain.BgtProjectRecruitApply;
import com.ruoyi.bgt.domain.dto.BgtAttendanceDayDTO;
import com.ruoyi.bgt.domain.dto.BgtProjectRecruitApplyConsentDTO;
import com.ruoyi.bgt.domain.dto.BgtProjectRecruitApplyQueryDTO;
import com.ruoyi.bgt.domain.dto.BgtScoreDTO;
import com.ruoyi.bgt.domain.vo.BgtProjectRecruitApplyVO;
import com.ruoyi.bgt.service.IBgtProjectRecruitApplyService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.wgz.bo.req.WgzAppPersonalBasicInformationReq;
import com.ruoyi.wgz.bo.res.WgzAppPersonalBasicInformationRes;
import com.ruoyi.wgz.service.IWgzUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * 包工头招工申请Controller
 *
 * @author ruoyi
 * @date 2025-02-18
 */
@Api(value = "App包工头招工申请控制器", tags = {"App包工头招工申请管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/app/bgt/apply")
public class AppBgtProjectRecruitApplyController extends BaseController {

    private final IBgtProjectRecruitApplyService iBgtProjectRecruitApplyService;

	private final IWgzUserService wgzUserService;

	@ApiOperation("App务工者列表")
	@GetMapping("/list")
	public AjaxResult<List<BgtProjectRecruitApplyVO>> list(@Validated BgtProjectRecruitApplyQueryDTO dto) {
		return AjaxResult.success(iBgtProjectRecruitApplyService.appQueryList(dto));
	}

	@ApiOperation("App务工者个人详情")
	@GetMapping()
	public AjaxResult<WgzAppPersonalBasicInformationRes> userPersonalBasicInformation(@Validated WgzAppPersonalBasicInformationReq req) {
		return AjaxResult.success(wgzUserService.userPersonalBasicInformation(req));
	}

    @ApiOperation("App务工者招工报名")
    @Log(title = "App务工者招工报名", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping()
    public AjaxResult<Void> add(@Validated @RequestBody BgtProjectRecruitApply bo) {
        return toAjax(iBgtProjectRecruitApplyService.insert(bo) ? 1 : 0);
    }

	@ApiOperation("App同意申请")
	@Log(title = "App同意申请", businessType = BusinessType.UPDATE)
	@RepeatSubmit
	@PutMapping()
	public AjaxResult<Void> consent(@Validated @RequestBody BgtProjectRecruitApplyConsentDTO dto) {
		return toAjax(iBgtProjectRecruitApplyService.consent(dto));
	}


	@ApiOperation("指定日期打卡记录")
	@GetMapping("/todayAttendanceList")
	public AjaxResult<List<BgtProjectRecruitApplyVO>> todayAttendanceList(@Validated BgtAttendanceDayDTO req) {
		return AjaxResult.success(iBgtProjectRecruitApplyService.todayAttendanceList(req));
	}


	@ApiOperation("App务工者退场")
	@Log(title = "App务工者退场", businessType = BusinessType.UPDATE)
	@RepeatSubmit
	@PutMapping("/quit/{id}")
	public AjaxResult<Void> quit(@NotNull(message = "主键不能为空")
									 @PathVariable("id") Long id) {
		return toAjax(iBgtProjectRecruitApplyService.quit(id) ? 1 : 0);
	}

	@ApiOperation("App务工者打分")
	@Log(title = "App务工者打分", businessType = BusinessType.UPDATE)
	@RepeatSubmit
	@PutMapping("/score")
	public AjaxResult<Void> score(@Validated @RequestBody BgtScoreDTO dto) {
		return toAjax(iBgtProjectRecruitApplyService.score(dto) ? 1 : 0);
	}

}
