namespace Adapters.Driving.Api.Types;

using Application.Enrollments.DTOs;
using Application.Enrollments.Queries;
using Application.Professors.DTOs;
using Application.Professors.Queries;
using Application.Students.DTOs;
using Application.Students.Queries;
using Application.Subjects.DTOs;
using Application.Subjects.Queries;
using MediatR;

public class Query
{
    [GraphQLDescription("Get all students")]
    public async Task<IReadOnlyList<StudentDto>> GetStudents(
        [Service] IMediator mediator,
        CancellationToken ct) =>
        await mediator.Send(new GetStudentsQuery(), ct);

    [GraphQLDescription("Get students with cursor-based pagination (keyset)")]
    public async Task<PagedResult<StudentPagedDto>> GetStudentsPaged(
        int? afterCursor,
        int pageSize,
        [Service] IMediator mediator,
        CancellationToken ct) =>
        await mediator.Send(new GetStudentsPagedQuery(afterCursor, pageSize), ct);

    [GraphQLDescription("Get student by ID")]
    public async Task<StudentDto> GetStudent(
        int id,
        [Service] IMediator mediator,
        CancellationToken ct) =>
        await mediator.Send(new GetStudentByIdQuery(id), ct);

    [GraphQLDescription("Get all subjects")]
    public async Task<IReadOnlyList<SubjectDto>> GetSubjects(
        [Service] IMediator mediator,
        CancellationToken ct) =>
        await mediator.Send(new GetSubjectsQuery(), ct);

    [GraphQLDescription("Get available subjects for a student")]
    public async Task<IReadOnlyList<AvailableSubjectDto>> GetAvailableSubjects(
        int studentId,
        [Service] IMediator mediator,
        CancellationToken ct) =>
        await mediator.Send(new GetAvailableSubjectsQuery(studentId), ct);

    [GraphQLDescription("Get all professors")]
    public async Task<IReadOnlyList<ProfessorDto>> GetProfessors(
        [Service] IMediator mediator,
        CancellationToken ct) =>
        await mediator.Send(new GetProfessorsQuery(), ct);

    [GraphQLDescription("Get classmates for a student by subject")]
    public async Task<IReadOnlyList<ClassmatesBySubjectDto>> GetClassmates(
        int studentId,
        [Service] IMediator mediator,
        CancellationToken ct) =>
        await mediator.Send(new GetClassmatesQuery(studentId), ct);
}
