namespace Adapters.Driving.Api.Types.Enrollments;

using Adapters.Driven.Persistence.DataLoaders;
using Domain.Entities;

[ObjectType<Enrollment>]
public static partial class EnrollmentType
{
    [GraphQLDescription("Student enrolled")]
    public static async Task<Student?> GetStudent(
        [Parent] Enrollment enrollment,
        StudentByIdDataLoader dataLoader,
        CancellationToken ct) =>
        await dataLoader.LoadAsync(enrollment.StudentId, ct);

    [GraphQLDescription("Subject enrolled in")]
    public static async Task<Subject?> GetSubject(
        [Parent] Enrollment enrollment,
        SubjectByIdDataLoader dataLoader,
        CancellationToken ct) =>
        await dataLoader.LoadAsync(enrollment.SubjectId, ct);
}
