package zone

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

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

// GetCPUAlignmentProfileRequest struct to get CPU alignment profile of zone
type GetCPUAlignmentProfileRequest struct {
	// ID of zone
	// Required: true
	ZoneID uint64 `url:"zone_id" json:"zone_id" validate:"required"`
}

// GetCPUAlignmentProfile gets CPU alignment profile of zone
func (e Zone) GetCPUAlignmentProfile(ctx context.Context, req GetCPUAlignmentProfileRequest) ([]CpuAlignmentProfile, error) {
	res, err := e.GetCPUAlignmentProfileRaw(ctx, req)
	if err != nil {
		return nil, err
	}

	var profiles []CpuAlignmentProfile

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

	return profiles, nil
}

// GetCPUAlignmentProfileRaw gets CPU alignment profile of zone as an array of bytes
func (e Zone) GetCPUAlignmentProfileRaw(ctx context.Context, req GetCPUAlignmentProfileRequest) ([]byte, error) {
	err := validators.ValidateRequest(req)
	if err != nil {
		return nil, validators.ValidationErrors(validators.GetErrors(err))
	}

	url := "/cloudbroker/zone/get_cpu_alignment_profile"

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