package backup

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

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

type BackupDisksWithSpeedRequest struct {
	// Compute ID
	// Required: true
	ComputeID uint64 `url:"compute_id" json:"compute_id" validate:"required"`
}

// Get backup disk list and speeds for a compute
func (b Backup) BackupDisksWithSpeed(ctx context.Context, req BackupDisksWithSpeedRequest) (ListDisksWithSpeed, error) {
	err := validators.ValidateRequest(req)
	if err != nil {
		return nil, validators.ValidationErrors(validators.GetErrors(err))
	}

	url := "/cloudbroker/backup/backup_disks_with_speed"

	res, err := b.client.DecortApiCallCtype(ctx, http.MethodPost, url, constants.MIMEJSON, req)
	if err != nil {
		return nil, err
	}

	result := make(ListDisksWithSpeed, 0)

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

	return result, nil
}
