package org.dromara.main.controller;

import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.satoken.utils.LoginHelper;
import org.dromara.common.web.core.BaseController;
import org.dromara.main.service.IMainBackCandidateService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * 背调候选人Controller
 * 主要处理学员端的Offer管理
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/main/backCandidate")
public class MainBackCandidateController extends BaseController {

    private final IMainBackCandidateService mainBackCandidateService;

    /**
     * 获取学员的Offer列表
     */
    @GetMapping("/offerList")
    public R<List<Map<String, Object>>> offerList() {
        Long studentId = LoginHelper.getUserId();
        if (studentId == null) {
            return R.fail("未登录");
        }
        List<Map<String, Object>> list = mainBackCandidateService.getStudentOfferList(studentId);
        return R.ok(list);
    }

    /**
     * 学员接受Offer
     */
    @PutMapping("/acceptOffer/{id}")
    public R<Void> acceptOffer(@PathVariable Long id) {
        Long studentId = LoginHelper.getUserId();
        if (studentId == null) {
            return R.fail("未登录");
        }
        Boolean result = mainBackCandidateService.acceptOffer(id, studentId);
        return toAjax(result);
    }

    /**
     * 学员拒绝Offer
     */
    @PutMapping("/rejectOffer/{id}")
    public R<Void> rejectOffer(@PathVariable Long id) {
        Long studentId = LoginHelper.getUserId();
        if (studentId == null) {
            return R.fail("未登录");
        }
        Boolean result = mainBackCandidateService.rejectOffer(id, studentId);
        return toAjax(result);
    }
}
