package zone

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

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

// TestCPUAlignmentProfileRequest struct to test CPU alignment profile for zone
type TestCPUAlignmentProfileRequest struct {
	// ID of zone
	// Required: true
	ZoneID uint64 `url:"zone_id" json:"zone_id" validate:"required"`

	// Hypervisor similarity in percentage
	// Default: 70
	// Required: false
	HypervisorSimilarityInPercentage uint64 `url:"hypervisor_similarity_in_percentage,omitempty" json:"hypervisor_similarity_in_percentage,omitempty"`
}

// TestCPUAlignmentProfile tests CPU alignment profile for zone
func (e Zone) TestCPUAlignmentProfile(ctx context.Context, req TestCPUAlignmentProfileRequest) (*TestCPUAlignmentProfileResult, error) {
	res, err := e.TestCPUAlignmentProfileRaw(ctx, req)
	if err != nil {
		return nil, err
	}

	result := TestCPUAlignmentProfileResult{}

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

	return &result, nil
}

// TestCPUAlignmentProfileRaw tests CPU alignment profile for zone and returns the result as an array of bytes
func (e Zone) TestCPUAlignmentProfileRaw(ctx context.Context, req TestCPUAlignmentProfileRequest) ([]byte, error) {
	err := validators.ValidateRequest(req)
	if err != nil {
		return nil, validators.ValidationErrors(validators.GetErrors(err))
	}

	url := "/cloudbroker/zone/test_cpu_alignment_profile"

	res, err := e.client.DecortApiCall(ctx, http.MethodPost, url, req)
	return res, err
}
