package segments

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

// GetRequest struct to get information about segment
type GetRequest struct {
	// ID of segment
	// Required: true
	SegmentID string `url:"segment_id" json:"segment_id" validate:"required"`

	// ID of access group
	// Required: false
	AccessGroupID string `url:"access_group_id,omitempty" json:"access_group_id,omitempty"`
}

// Get gets segment details as a SegmentResponse struct
func (s Segments) Get(ctx context.Context, req GetRequest) (*SegmentResponse, error) {
	res, err := s.GetRaw(ctx, req)
	if err != nil {
		return nil, err
	}

	info := SegmentResponse{}

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

	return &info, nil
}

// GetRaw gets segment details as an array of bytes
func (s Segments) GetRaw(ctx context.Context, req GetRequest) ([]byte, error) {

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

	url := "/sdn/segment/get"

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