package acsgroups

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

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

// GetGroupRequest struct to get an access group
type GetGroupRequest struct {
	// ID of the access group
	// Required: true
	GroupID string `url:"access_group_id" json:"access_group_id" validate:"required"`
}

// Info about access group
func (i AccessGroups) Get(ctx context.Context, req GetGroupRequest) (*AccessGroup, error) {
	res, err := i.GetRaw(ctx, req)
	if err != nil {
		return nil, err
	}

	group := AccessGroup{}

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

	return &group, nil
}

// GetRaw gets a details of group as an array of bytes
func (a AccessGroups) GetRaw(ctx context.Context, req GetGroupRequest) ([]byte, error) {

	if err := validators.ValidateRequest(req); err != nil {
		return nil, validators.ValidationErrors(validators.GetErrors(err))
	}

	url := "/sdn/access_group/get"

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