package resolver

// 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

import (
	"context"

	"github.com/cloudoperators/heureka/internal/api/graphql/graph"
	"github.com/cloudoperators/heureka/internal/api/graphql/graph/baseResolver"
	"github.com/cloudoperators/heureka/internal/api/graphql/graph/model"
	"github.com/cloudoperators/heureka/internal/util"
	"github.com/sirupsen/logrus"
)

// SPDX-FileCopyrightText: 2025 SAP SE or an SAP affiliate company and Greenhouse contributors
// SPDX-License-Identifier: Apache-2.0

func (r *evidenceResolver) Author(ctx context.Context, obj *model.Evidence) (*model.User, error) {
	childIds, err := util.ConvertStrToIntSlice([]*string{obj.AuthorID})

	if err != nil {
		logrus.WithField("obj", obj).Error("EvidenceResolver: Error while parsing childIds'")
		return nil, err
	}

	return baseResolver.SingleUserBaseResolver(r.App, ctx, &model.NodeParent{
		Parent:     obj,
		ParentName: model.EvidenceNodeName,
		ChildIds:   childIds,
	})
}

func (r *evidenceResolver) Activity(ctx context.Context, obj *model.Evidence) (*model.Activity, error) {
	childIds, err := util.ConvertStrToIntSlice([]*string{obj.ActivityID})

	if err != nil {
		logrus.WithField("obj", obj).Error("EvidenceResolver: Error while parsing childIds'")
		return nil, err
	}

	return baseResolver.SingleActivityBaseResolver(r.App, ctx, &model.NodeParent{
		Parent:     obj,
		ParentName: model.EvidenceNodeName,
		ChildIds:   childIds,
	})
}

func (r *evidenceResolver) IssueMatches(ctx context.Context, obj *model.Evidence, filter *model.IssueMatchFilter, first *int, after *string) (*model.IssueMatchConnection, error) {
	return baseResolver.IssueMatchBaseResolver(r.App, ctx, filter, first, after, nil, &model.NodeParent{
		Parent:     obj,
		ParentName: model.EvidenceNodeName,
	})
}

func (r *Resolver) Evidence() graph.EvidenceResolver { return &evidenceResolver{r} }

type evidenceResolver struct{ *Resolver }
