package utilities

import (
	"context"
	"fmt"

	"github.com/hashicorp/terraform-plugin-framework/diag"
	"github.com/hashicorp/terraform-plugin-log/tflog"
	"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/flipgroup"
	"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/client"
)

func FlipgroupDataSourceCheckPresence(ctx context.Context, fgId uint64, c *client.Client) (*flipgroup.RecordFLIPGroup, diag.Diagnostics) {
	tflog.Info(ctx, fmt.Sprintf("FlipgroupDataSourceCheckPresence: Get info about flipgroup with ID - %v", fgId))

	diags := diag.Diagnostics{}

	recordFG, err := c.CloudAPI().FLIPGroup().Get(ctx, flipgroup.GetRequest{FLIPGroupID: fgId})
	if err != nil {
		diags.AddError(fmt.Sprintf("Cannot get info about flipgroup with ID %v", fgId), err.Error())
		return nil, diags
	}

	tflog.Info(ctx, "FlipgroupDataSourceCheckPresence: response from CloudAPI().FLIPGroup().Get", map[string]any{"flipgroup_id": fgId, "response": recordFG})

	return recordFG, nil
}
