package zone

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

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

// GetRequest struct to get detailed information about zone
type GetRequest struct {
	// ID of zone
	// Required: true
	ID uint64 `url:"id" json:"id" validate:"required"`
}

// Get gets detailed information about zone struct
func (e Zone) Get(ctx context.Context, req GetRequest) (*RecordZone, error) {
	res, err := e.GetRaw(ctx, req)
	if err != nil {
		return nil, err
	}

	info := RecordZone{}

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

	return &info, nil
}

// GetRaw gets detailed information about zone as an array of bytes
func (e Zone) GetRaw(ctx context.Context, req GetRequest) ([]byte, error) {
	err := validators.ValidateRequest(req)
	if err != nil {
		return nil, validators.ValidationErrors(validators.GetErrors(err))
	}

	url := "/cloudapi/zone/get"

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