-- name: CreateClassroom :one
INSERT INTO classrooms (
    teacher_id,
    name,
    code,
    description
) VALUES (
    $1,
    $2,
    $3,
    $4
)
RETURNING *;

-- name: ListClassroomsByTeacher :many
SELECT *
FROM classrooms
WHERE teacher_id = $1
ORDER BY created_at DESC;

-- name: AddStudentToClassroom :exec
INSERT INTO classroom_students (
    classroom_id,
    student_id
) VALUES (
    $1,
    $2
)
ON CONFLICT (classroom_id, student_id) DO NOTHING;

-- name: ListStudentsForClassroom :many
SELECT u.*
FROM classroom_students cs
JOIN users u ON u.id = cs.student_id
WHERE cs.classroom_id = $1
ORDER BY u.full_name ASC;
