// 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 dnsFirewallResolver struct {
	client DnsFirewallClient
	sdkresolvers.BaseNameResolver
}

func DnsFirewallResolver(name string, client DnsFirewallClient, opts ...sdkresolvers.ResolveOption) sdkresolvers.Resolver {
	return &dnsFirewallResolver{
		client:           client,
		BaseNameResolver: sdkresolvers.NewBaseNameResolver(name, "DnsFirewall", opts...),
	}
}

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

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