package compute

import (
	"context"
	"encoding/json"
	"net/http"

	"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)

// GetCloneStatusRequest struct to get information about compute clone status
type GetCloneStatusRequest struct {
	// ID of compute instance
	// Required: true
	ComputeID string `url:"compute_id" json:"compute_id" validate:"required"`
}

// GetCloneStatus gets information about compute clone status as a RecordCloneStatus struct
func (c Compute) GetCloneStatus(ctx context.Context, req GetCloneStatusRequest) ([]RecordCloneStatus, error) {
	err := validators.ValidateRequest(req)
	if err != nil {
		return nil, validators.ValidationErrors(validators.GetErrors(err))
	}

	url := "/cloudbroker/compute/clone_status"

	res, err := c.client.DecortApiCall(ctx, http.MethodGet, url, req)
	if err != nil {
		return nil, err
	}

	cloneStatus := make([]RecordCloneStatus, 0)

	err = json.Unmarshal(res, &cloneStatus)
	if err != nil {
		return nil, err
	}

	return cloneStatus, nil
}
