package com.reading.platform.controller.teacher;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.reading.platform.common.response.PageResult;
import com.reading.platform.common.response.Result;
import com.reading.platform.common.security.SecurityUtils;
import com.reading.platform.entity.Course;
import com.reading.platform.service.CourseService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "Teacher - Course", description = "Course APIs for Teacher")
@RestController
@RequestMapping("/api/teacher/courses")
@RequiredArgsConstructor
public class TeacherCourseController {

    private final CourseService courseService;

    @Operation(summary = "Get course by ID")
    @GetMapping("/{id}")
    public Result<Course> getCourse(@PathVariable Long id) {
        return Result.success(courseService.getCourseById(id));
    }

    @Operation(summary = "Get course page")
    @GetMapping
    public Result<PageResult<Course>> getCoursePage(
            @RequestParam(required = false) Integer pageNum,
            @RequestParam(required = false) Integer pageSize,
            @RequestParam(required = false) String keyword,
            @RequestParam(required = false) String category) {
        Long tenantId = SecurityUtils.getCurrentTenantId();
        Page<Course> page = courseService.getCoursePage(tenantId, pageNum, pageSize, keyword, category, "published");
        return Result.success(PageResult.of(page));
    }

    @Operation(summary = "Get all courses")
    @GetMapping("/all")
    public Result<List<Course>> getAllCourses() {
        Long tenantId = SecurityUtils.getCurrentTenantId();
        return Result.success(courseService.getCoursesByTenantId(tenantId));
    }

}
