import { Controller, Get } from '@nestjs/common';
import { ApiOperation, ApiTags } from '@nestjs/swagger';
import { CourseResourcesService } from './course_resources.service';

@ApiTags('course-resources')
@Controller('course-resources')
export class CourseResourcesController {
  constructor(private readonly courseResourcesService: CourseResourcesService) {}

  @Get('datawhale')
  @ApiOperation({
    summary: '获取Datawhale课程资源',
    description: '返回后端定时同步缓存的Datawhale学习中心课程列表。',
  })
  async getDatawhaleCourses() {
    const data = await this.courseResourcesService.getDatawhaleCourses();
    return {
      success: true,
      data,
      message: '课程资源获取成功',
    };
  }

  @Get('datawhale/sync')
  @ApiOperation({
    summary: '手动同步Datawhale课程资源',
    description: '开发调试用：立即从Datawhale同步最新课程并返回缓存结果。',
  })
  async syncDatawhaleCourses() {
    const data = await this.courseResourcesService.syncNow();
    return {
      success: true,
      data,
      message: '课程资源同步成功',
    };
  }
}
