import { Get, Body, Post, Route, Tags, SuccessResponse, Response, Delete, Controller, Security, Request, Put, Path, Query } from 'tsoa';
import { ValidationError } from '../middleware/errorHandler';
import { listCourseResponse, getCourseResponse } from '../types/courses.types';
import { CoursesService } from '../services/courses.service';

@Route('api/courses')
@Tags('Courses')
export class CoursesController {
    private coursesService = new CoursesService();

    /**
     * ดึงรายการคอร์สทั้งหมด (สามารถ filter ด้วย category_id ได้)
     * Get all courses (can filter by category_id)
     * @param category_id - รหัสหมวดหมู่ / Category ID (optional)
     */
    @Get()
    @SuccessResponse('200', 'Courses fetched successfully')
    @Response('401', 'Invalid or expired token')
    public async listCourses(@Query() category_id?: number): Promise<listCourseResponse> {
        return await this.coursesService.ListCourses(category_id);
    }

    /**
     * ดึงข้อมูลคอร์สตาม ID
     * Get course by ID
     * @param id - รหัสคอร์ส / Course ID
     */
    @Get('{id}')
    @SuccessResponse('200', 'Course fetched successfully')
    @Response('404', 'Course not found')
    public async getCourseById(@Path() id: number): Promise<getCourseResponse> {
        return await this.coursesService.GetCourseById(id);
    }
}
