<commit_before>package collection

import (
	"encoding/json"
	"errors"
	"github.com/kuzzleio/sdk-go/types"
	"strconv"
	"fmt"
)

type IDocument interface {
	Save()
	Refresh()
	SetContent()
	Publish()
	Exists()
	SetHeaders()
	Delete()
}

type CollectionDocument struct {
	Collection Collection `json:"-"`
	Document   types.Document
}

type DocumentContent map[string]interface{}

func (documentContent DocumentContent) ToString() string {
	s, _ := json.Marshal(documentContent)

	return string(s)
}

/*
  Helper function to initialize a document into CollectionDocument using fetch query.
 */
func (cd CollectionDocument) Fetch(id string, ) (CollectionDocument, error) {
	if id == "" {
		return cd, errors.New("CollectionDocument.Fetch: missing document id")
	}

	doc, err := cd.Collection.FetchDocument(id, nil)

	if err != nil {
		return cd, errors.New("CollectionDocument.Fetch: an error occurred: " + fmt.Sprint(err))
	}

	cd.Document = doc

	return cd, nil
}

/*
  Listens to events concerning this document. Has no effect if the document does not have an ID
  (i.e. if the document has not yet been created as a persisted document).
 */
func (cd CollectionDocument) Subscribe(options types.RoomOptions, ch chan<- types.KuzzleNotification) chan types.SubscribeResponse {<commit_msg>Fixed trailing coma leftover in func signature<commit_after>package collection

import (
	"encoding/json"
	"errors"
	"fmt"
	"github.com/kuzzleio/sdk-go/types"
	"strconv"
)

type IDocument interface {
	Save()
	Refresh()
	SetContent()
	Publish()
	Exists()
	SetHeaders()
	Delete()
}

type CollectionDocument struct {
	Collection Collection `json:"-"`
	Document   types.Document
}

type DocumentContent map[string]interface{}

func (documentContent DocumentContent) ToString() string {
	s, _ := json.Marshal(documentContent)

	return string(s)
}

/*
  Helper function to initialize a document into CollectionDocument using fetch query.
 */
func (cd CollectionDocument) Fetch(id string) (CollectionDocument, error) {
	if id == "" {
		return cd, errors.New("CollectionDocument.Fetch: missing document id")
	}

	doc, err := cd.Collection.FetchDocument(id, nil)

	if err != nil {
		return cd, errors.New("CollectionDocument.Fetch: an error occurred: " + fmt.Sprint(err))
	}

	cd.Document = doc

	return cd, nil
}

/*
  Listens to events concerning this document. Has no effect if the document does not have an ID
  (i.e. if the document has not yet been created as a persisted document).
 */
func (cd CollectionDocument) Subscribe(options types.RoomOptions, ch chan<- types.KuzzleNotification) chan types.SubscribeResponse {
{'fraction_non_alphanumeric': 0.10880430603613994, 'fraction_numerical': 0.0, 'mean_word_length': 4.583690987124464, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5179271', 'n_tokens_mistral': 806, 'n_tokens_neox': 774, 'n_words': 252}