package org.xyzh.study.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.xyzh.api.study.record.LearningRecordService;
import org.xyzh.common.core.domain.ResultDomain;
import org.xyzh.common.dto.study.TbLearningRecord;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.PathVariable;


/**
 * @description 学习记录控制器
 * @filename LearningRecordController.java
 * @author yslg
 * @copyright xyzh
 * @since 2025-10-15
 */
@RestController
@RequestMapping("/study/records")
public class LearningRecordController {
    private static final Logger logger = LoggerFactory.getLogger(LearningRecordController.class);

    @Autowired
    private LearningRecordService learningRecordService;

    /**
     * 获取学习记录
     */
    @PostMapping("/list")
    public ResultDomain<TbLearningRecord> getLearningRecordList(@RequestBody TbLearningRecord learningRecord) {
        return learningRecordService.getLearningRecord(learningRecord);
    }

    /**
     * 创建学习记录
     */
    @PostMapping("/record")
    public ResultDomain<TbLearningRecord> insertLearningRecord(@RequestBody TbLearningRecord record) {
        return learningRecordService.insertLearningRecord(record);
    }

    /**
     * 更新学习记录
     */
    @PutMapping("/record")
    public ResultDomain<TbLearningRecord> updateLearningRecord(@RequestBody TbLearningRecord record) {
        return learningRecordService.updateLearningRecord(record);
    }

    /**
     * 删除学习记录
     */
    @DeleteMapping("/record")
    public ResultDomain<Boolean> deleteLearningRecord(@RequestBody TbLearningRecord learningRecord) {
        return learningRecordService.deleteLearningRecord(learningRecord.getID());
    }

    @PutMapping("/complete")
    public ResultDomain<TbLearningRecord> markLearningComplete(@RequestBody TbLearningRecord learningRecord) {
        return learningRecordService.markLearningComplete(learningRecord);
    }

    /**
     * 查询用户课程的学习记录
     */
    @PostMapping("/course/records")
    public ResultDomain<TbLearningRecord> getCourseLearningRecord(@RequestBody TbLearningRecord learningRecord) {
        
        return learningRecordService.getCourseLearningRecord(learningRecord);
    }
}
