package segments

import (
	"context"

	"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
	"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/sdn/segments"
	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)

func utilitySegmentGetStatusCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (string, error) {
	c := m.(*controller.ControllerCfg)

	req := segments.GetStatusRequest{}

	if d.Id() != "" {
		req.SegmentID = d.Id()
	} else {
		req.SegmentID = d.Get("segment_id").(string)
	}

	if version, ok := d.GetOk("version"); ok {
		req.VersionID = uint64(version.(int))
	}

	if detailed, ok := d.GetOk("detailed"); ok {
		req.Detailed = detailed.(bool)
	}

	segment, err := c.SDN().Segments().GetStatus(ctx, req)
	if err != nil {
		return "", err
	}

	return segment, nil
}
