// Code generated by sdkgen-v2. DO NOT EDIT.
package dnssdk

import (
	"context"

	dns "github.com/yandex-cloud/go-genproto/yandex/cloud/dns/v1"
	"github.com/yandex-cloud/go-sdk/v2/pkg/sdkresolvers"
)

type dnsZoneResolver struct {
	client DnsZoneClient
	sdkresolvers.BaseNameResolver
}

func DnsZoneResolver(name string, client DnsZoneClient, opts ...sdkresolvers.ResolveOption) sdkresolvers.Resolver {
	return &dnsZoneResolver{
		client:           client,
		BaseNameResolver: sdkresolvers.NewBaseNameResolver(name, "DnsZone", opts...),
	}
}

func (r *dnsZoneResolver) Run(ctx context.Context) error {
	err := r.EnsureFolderID()
	if err != nil {
		return err
	}

	resp := r.client.Iterator(ctx, &dns.ListDnsZonesRequest{
		FolderId: r.FolderID(),
		Filter:   sdkresolvers.CreateResolverFilter("name", r.Name),
		PageSize: sdkresolvers.DefaultResolverPageSize,
	})
	return r.FindName(resp.TakeAll())
}
