// Code generated by ent, DO NOT EDIT.

package ent

import (
	"context"

	"github.com/99designs/gqlgen/graphql"
)

func (_m *Attestation) AttestationCollection(ctx context.Context) (*AttestationCollection, error) {
	result, err := _m.Edges.AttestationCollectionOrErr()
	if IsNotLoaded(err) {
		result, err = _m.QueryAttestationCollection().Only(ctx)
	}
	return result, err
}

func (_m *AttestationCollection) Attestations(ctx context.Context) (result []*Attestation, err error) {
	if fc := graphql.GetFieldContext(ctx); fc != nil && fc.Field.Alias != "" {
		result, err = _m.NamedAttestations(graphql.GetFieldContext(ctx).Field.Alias)
	} else {
		result, err = _m.Edges.AttestationsOrErr()
	}
	if IsNotLoaded(err) {
		result, err = _m.QueryAttestations().All(ctx)
	}
	return result, err
}

func (_m *AttestationCollection) Statement(ctx context.Context) (*Statement, error) {
	result, err := _m.Edges.StatementOrErr()
	if IsNotLoaded(err) {
		result, err = _m.QueryStatement().Only(ctx)
	}
	return result, err
}

func (_m *AttestationPolicy) Statement(ctx context.Context) (*Statement, error) {
	result, err := _m.Edges.StatementOrErr()
	if IsNotLoaded(err) {
		result, err = _m.QueryStatement().Only(ctx)
	}
	return result, MaskNotFound(err)
}

func (_m *Dsse) Statement(ctx context.Context) (*Statement, error) {
	result, err := _m.Edges.StatementOrErr()
	if IsNotLoaded(err) {
		result, err = _m.QueryStatement().Only(ctx)
	}
	return result, MaskNotFound(err)
}

func (_m *Dsse) Signatures(ctx context.Context) (result []*Signature, err error) {
	if fc := graphql.GetFieldContext(ctx); fc != nil && fc.Field.Alias != "" {
		result, err = _m.NamedSignatures(graphql.GetFieldContext(ctx).Field.Alias)
	} else {
		result, err = _m.Edges.SignaturesOrErr()
	}
	if IsNotLoaded(err) {
		result, err = _m.QuerySignatures().All(ctx)
	}
	return result, err
}

func (_m *Dsse) PayloadDigests(ctx context.Context) (result []*PayloadDigest, err error) {
	if fc := graphql.GetFieldContext(ctx); fc != nil && fc.Field.Alias != "" {
		result, err = _m.NamedPayloadDigests(graphql.GetFieldContext(ctx).Field.Alias)
	} else {
		result, err = _m.Edges.PayloadDigestsOrErr()
	}
	if IsNotLoaded(err) {
		result, err = _m.QueryPayloadDigests().All(ctx)
	}
	return result, err
}

func (_m *PayloadDigest) Dsse(ctx context.Context) (*Dsse, error) {
	result, err := _m.Edges.DsseOrErr()
	if IsNotLoaded(err) {
		result, err = _m.QueryDsse().Only(ctx)
	}
	return result, MaskNotFound(err)
}

func (_m *Signature) Dsse(ctx context.Context) (*Dsse, error) {
	result, err := _m.Edges.DsseOrErr()
	if IsNotLoaded(err) {
		result, err = _m.QueryDsse().Only(ctx)
	}
	return result, MaskNotFound(err)
}

func (_m *Signature) Timestamps(ctx context.Context) (result []*Timestamp, err error) {
	if fc := graphql.GetFieldContext(ctx); fc != nil && fc.Field.Alias != "" {
		result, err = _m.NamedTimestamps(graphql.GetFieldContext(ctx).Field.Alias)
	} else {
		result, err = _m.Edges.TimestampsOrErr()
	}
	if IsNotLoaded(err) {
		result, err = _m.QueryTimestamps().All(ctx)
	}
	return result, err
}

func (_m *Statement) Subjects(
	ctx context.Context, after *Cursor, first *int, before *Cursor, last *int, orderBy *SubjectOrder, where *SubjectWhereInput,
) (*SubjectConnection, error) {
	opts := []SubjectPaginateOption{
		WithSubjectOrder(orderBy),
		WithSubjectFilter(where.Filter),
	}
	alias := graphql.GetFieldContext(ctx).Field.Alias
	totalCount, hasTotalCount := _m.Edges.totalCount[0][alias]
	if nodes, err := _m.NamedSubjects(alias); err == nil || hasTotalCount {
		pager, err := newSubjectPager(opts, last != nil)
		if err != nil {
			return nil, err
		}
		conn := &SubjectConnection{Edges: []*SubjectEdge{}, TotalCount: totalCount}
		conn.build(nodes, pager, after, first, before, last)
		return conn, nil
	}
	return _m.QuerySubjects().Paginate(ctx, after, first, before, last, opts...)
}

func (_m *Statement) Policy(ctx context.Context) (*AttestationPolicy, error) {
	result, err := _m.Edges.PolicyOrErr()
	if IsNotLoaded(err) {
		result, err = _m.QueryPolicy().Only(ctx)
	}
	return result, MaskNotFound(err)
}

func (_m *Statement) AttestationCollections(ctx context.Context) (*AttestationCollection, error) {
	result, err := _m.Edges.AttestationCollectionsOrErr()
	if IsNotLoaded(err) {
		result, err = _m.QueryAttestationCollections().Only(ctx)
	}
	return result, MaskNotFound(err)
}

func (_m *Statement) Dsse(ctx context.Context) (result []*Dsse, err error) {
	if fc := graphql.GetFieldContext(ctx); fc != nil && fc.Field.Alias != "" {
		result, err = _m.NamedDsse(graphql.GetFieldContext(ctx).Field.Alias)
	} else {
		result, err = _m.Edges.DsseOrErr()
	}
	if IsNotLoaded(err) {
		result, err = _m.QueryDsse().All(ctx)
	}
	return result, err
}

func (_m *Subject) SubjectDigests(ctx context.Context) (result []*SubjectDigest, err error) {
	if fc := graphql.GetFieldContext(ctx); fc != nil && fc.Field.Alias != "" {
		result, err = _m.NamedSubjectDigests(graphql.GetFieldContext(ctx).Field.Alias)
	} else {
		result, err = _m.Edges.SubjectDigestsOrErr()
	}
	if IsNotLoaded(err) {
		result, err = _m.QuerySubjectDigests().All(ctx)
	}
	return result, err
}

func (_m *Subject) Statement(ctx context.Context) (*Statement, error) {
	result, err := _m.Edges.StatementOrErr()
	if IsNotLoaded(err) {
		result, err = _m.QueryStatement().Only(ctx)
	}
	return result, MaskNotFound(err)
}

func (_m *SubjectDigest) Subject(ctx context.Context) (*Subject, error) {
	result, err := _m.Edges.SubjectOrErr()
	if IsNotLoaded(err) {
		result, err = _m.QuerySubject().Only(ctx)
	}
	return result, MaskNotFound(err)
}

func (_m *Timestamp) Signature(ctx context.Context) (*Signature, error) {
	result, err := _m.Edges.SignatureOrErr()
	if IsNotLoaded(err) {
		result, err = _m.QuerySignature().Only(ctx)
	}
	return result, MaskNotFound(err)
}
