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 InfoRequest struct {
	// Compute ID
	// Required: true
	ComputeID uint64 `url:"compute_id" json:"compute_id" validate:"required"`
}

// Information about all backups running on the machine
func (b Backup) Info(ctx context.Context, req InfoRequest) (*TotalBackupsInfo, error) {
	err := validators.ValidateRequest(req)
	if err != nil {
		return nil, validators.ValidationErrors(validators.GetErrors(err))
	}

	url := "/cloudbroker/backup/info"

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

	result := TotalBackupsInfo{}

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

	return &result, nil
}
