package cn.iocoder.yudao.module.course.controller.admin;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.course.entity.SchoolStudentCommissionRecord;
import cn.iocoder.yudao.module.course.service.SchoolStudentCommissionRecordService;
import cn.iocoder.yudao.module.course.vo.SchoolStudentCommissionRecordVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@RestController
@RequestMapping("/commissionRecord")
@Validated
public class SchoolStudentCommissionRecordController {
    @Autowired
    private SchoolStudentCommissionRecordService commissionRecordService;


    @PostMapping("/create")
    public CommonResult<?> createRecord(@RequestBody SchoolStudentCommissionRecord record) {

        return success(commissionRecordService.createRecord(record));
    }

    @PutMapping("/update")
    public CommonResult<Boolean> updateRecord(@RequestBody SchoolStudentCommissionRecord record) {
        return success(commissionRecordService.updateRecord(record));
    }

    @DeleteMapping("/delete")
    public CommonResult<Boolean> deleteRecord(@RequestParam("id") Long id) {
        return success(commissionRecordService.deleteRecord(id));
    }

    @GetMapping("/get")
    public CommonResult<?> getRecord(@RequestParam("id") Long id) {
        SchoolStudentCommissionRecord record = commissionRecordService.getRecordById(id);
        return success(record);
    }

    @GetMapping("/list-by-student")
    public CommonResult<List<SchoolStudentCommissionRecord>> getRecordsByStudentId(@RequestParam("studentId") Long studentId) {
        List<SchoolStudentCommissionRecord> list = commissionRecordService.getRecordsByStudentId(studentId);
        return success(list);
    }

    @GetMapping("/list-by-coach")
    public CommonResult<List<SchoolStudentCommissionRecord>> getRecordsByCoachId(@RequestParam("coachId") Long coachId) {
        List<SchoolStudentCommissionRecord> list = commissionRecordService.getRecordsByCoachId(coachId);
        return success(list);
    }

    @PutMapping("/update-grant-status")
    public CommonResult<Boolean> updateGrantStatus(@RequestBody SchoolStudentCommissionRecord reqVO) {
        return success(commissionRecordService.updateGrantStatus(reqVO.getId(), reqVO.getIsGrant()));
    }
}
