package secpolicies

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

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

// GetRequest struct to get information about security policy
type GetRequest struct {
	// ID a security policy
	// Required: true
	ID string `url:"security_policy_id" json:"security_policy_id" validate:"required"`
}

// Get gets security policy
func (a SecurityPolicies) Get(ctx context.Context, req GetRequest) (*SecurityPolicySummary, error) {
	res, err := a.GetRaw(ctx, req)
	if err != nil {
		return nil, err
	}

	info := SecurityPolicySummary{}

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

	return &info, nil

}

// GetRaw gets address pool details as an array of bytes
func (a SecurityPolicies) GetRaw(ctx context.Context, req GetRequest) ([]byte, error) {
	err := validators.ValidateRequest(req)
	if err != nil {
		return nil, validators.ValidationErrors(validators.GetErrors(err))
	}

	url := "/sdn/security_policies/get"

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