package response

import (
	"time"

	"gitlab.ost.ch/marketminds/marketminds/pkg/entity"
)

type nerResult struct {
	Entities  []*namedEntity `json:"entities"`
	CreatedAt string         `json:"created_at"`
}

func newNerResult(input []*entity.NERResult) *nerResult {
	var createdAt string = ""
	var first *entity.NERResult = input[0]

	if !first.CreatedAt.IsZero() {
		createdAt = first.CreatedAt.UTC().Format(time.RFC3339)
	}

	var entities []*namedEntity
	for _, entity := range input {
		entities = append(entities, newNamedEntity(entity.NamedEntity))
	}

	return &nerResult{
		Entities:  entities,
		CreatedAt: createdAt,
	}
}
