package disks

import (
	"context"

	"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
	log "github.com/sirupsen/logrus"
	"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/disks"
	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)

func utilityDiskListTypesCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*disks.ListTypes, error) {
	c := m.(*controller.ControllerCfg)
	req := disks.ListTypesRequest{
		Detailed: false,
	}

	if sortBy, ok := d.GetOk("sort_by"); ok {
		req.SortBy = sortBy.(string)
	}
	if page, ok := d.GetOk("page"); ok {
		req.Page = uint64(page.(int))
	}
	if size, ok := d.GetOk("size"); ok {
		req.Size = uint64(size.(int))
	}

	log.Debugf("utilityDiskListTypesCheckPresence: load disk list Types Detailed")
	typesList, err := c.CloudBroker().Disks().ListTypes(ctx, req)
	if err != nil {
		return nil, err
	}

	return typesList, nil
}
