package vins

import (
	"encoding/json"

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

// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.
//
// In order to serialize with indent make sure to follow these guidelines:
//   - First argument -> prefix
//   - Second argument -> indent
func (lv ListVINS) Serialize(params ...string) (serialization.Serialized, error) {
	if len(lv.Data) == 0 {
		return []byte{}, nil
	}

	if len(params) > 1 {
		prefix := params[0]
		indent := params[1]

		return json.MarshalIndent(lv, prefix, indent)
	}

	return json.Marshal(lv)
}

// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.
//
// In order to serialize with indent make sure to follow these guidelines:
//   - First argument -> prefix
//   - Second argument -> indent
func (iv ItemVINS) Serialize(params ...string) (serialization.Serialized, error) {
	if len(params) > 1 {
		prefix := params[0]
		indent := params[1]

		return json.MarshalIndent(iv, prefix, indent)
	}

	return json.Marshal(iv)
}
