package graphql

// This file will be automatically regenerated based on the schema, any resolver implementations
// will be copied through when generating and any unknown code will be moved to the end.
// Code generated by github.com/99designs/gqlgen version v0.17.41

import (
	"context"

	"github.com/programme-lv/backend/internal/services/langs"
	"github.com/programme-lv/backend/internal/services/objects"
)

// ListLanguages is the resolver for the listLanguages field.
func (r *queryResolver) ListLanguages(ctx context.Context, enabled *bool) ([]*ProgrammingLanguage, error) {
	languages, err := langs.ListEnabledProgrammingLanguages(r.PostgresDB)
	if err != nil {
		return nil, err
	}

	// convert to graphql type
	var gqlLangs []*ProgrammingLanguage
	for _, lang := range languages {
		gqlLangs = append(gqlLangs, internalProgrammingLanguageToGraphQL(&lang))
	}

	return gqlLangs, nil
}

func internalProgrammingLanguageToGraphQL(lang *objects.ProgrammingLanguage) *ProgrammingLanguage {
	return &ProgrammingLanguage{
		ID:       lang.ID,
		FullName: lang.Name,
		MonacoID: lang.MonacoID,
		Enabled:  true,
	}
}
