package qospolicy

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

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

type GetRequest struct {
	// QoS policy ID
	// Required: true
	QoSPolicyID uint64 `url:"qos_policy_id" json:"qos_policy_id" validate:"required"`
}

func (qp QoSPolicy) Get(ctx context.Context, req GetRequest) (*RecordQoSPolicy, error) {
	res, err := qp.GetRaw(ctx, req)
	if err != nil {
		return nil, err
	}

	info := RecordQoSPolicy{}

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

	return &info, nil
}

func (qp QoSPolicy) GetRaw(ctx context.Context, req GetRequest) ([]byte, error) {
	err := validators.ValidateRequest(req)
	if err != nil {
		return nil, validators.ValidationErrors(validators.GetErrors(err))
	}

	url := "/cloudapi/network_qos_policy/get"

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