// CreateContentObject creates a content object from the given payload.
CreateContentObject creates a content object from the given payload.
// CreateContentObject creates a content object from the given payload .
func (g *Generator) CreateContentObject(payload *subject.Payload) (vocab.Document, error) {
	if payload.CoreIndex == "" {
		return nil, fmt.Errorf("payload is missing core index")
	}
	if len(payload.PreviousAnchors) == 0 {
		return nil, fmt.Errorf("payload is missing previous anchors")
	}
	var resources []*resource
	for _, value := range payload.PreviousAnchors {
		logger.Debugf("Resource - Key [%s] Value [%s]", value.Suffix, value.Anchor)
		var res *resource
		if value.Anchor == "" {
			res = &resource{ID: fmt.Sprintf("%s:%s:%s", multihashPrefix, unpublishedLabel, value.Suffix)}
		} else {
			parts := strings.Split(value.Anchor, separator)
			if len(parts) != hashlinkParts {
				return nil, fmt.Errorf("invalid number of parts for previous anchor hashlink[%s] for suffix[%s]: expected 3, got %d", value, value.Suffix, len(parts)) 
			}
			pos := strings.LastIndex(value.Anchor, ":")
			if pos == -1 {
				return nil, fmt.Errorf("invalid previous anchor hashlink[%s] - must contain separator ':'", value)
			}
			prevAnchor := parts[0] + separator + parts[1]
			res = &resource{ID: fmt.Sprintf("%s:%s:%s", multihashPrefix, parts[1], value.Suffix), PreviousAnchor: prevAnchor}
		}
		resources = append(resources, res)
	}
	contentObj := &contentObject{
		Subject: payload.CoreIndex,
		Properties: &propertiesType{
			Generator: g.id,
			Resources: resources,
		},
	}
	contentObjDoc, err := vocab.MarshalToDoc(contentObj)
	if err != nil {
		return nil, fmt.Errorf("marshal content object to document: %w", err)
	}
	return contentObjDoc, nil
}
func ( g * Generator ) CreateContentObject ( payload * subject . Payload ) ( vocab . Document , error ) { if payload . CoreIndex == " " { return nil , fmt . Errorf ( " " ) } if len ( payload . PreviousAnchors ) == 0 { return nil , fmt . Errorf ( " " ) } var resources [ ] * resource for _ , value := range payload . PreviousAnchors { logger . Debugf ( " " , value . Suffix , value . Anchor ) var res * resource if value . Anchor == " " { res = & resource { ID : fmt . Sprintf ( " " , multihashPrefix , unpublishedLabel , value . Suffix ) } } else { parts := strings . Split ( value . Anchor , separator ) if len ( parts ) != hashlinkParts { return nil , fmt . Errorf ( " " , value , value . Suffix , len ( parts ) ) } pos := strings . LastIndex ( value . Anchor , " " ) if pos == - 1 { return nil , fmt . Errorf ( " " , value ) } prevAnchor := parts [ 0 ] + separator + parts [ 1 ] res = & resource { ID : fmt . Sprintf ( " " , multihashPrefix , parts [ 1 ] , value . Suffix ) , PreviousAnchor : prevAnchor } } resources = append ( resources , res ) } contentObj := & contentObject { Subject : payload . CoreIndex , Properties : & propertiesType { Generator : g . id , Resources : resources , } , } contentObjDoc , err := vocab . MarshalToDoc ( contentObj ) if err != nil { return nil , fmt . Errorf ( " " , err ) } return contentObjDoc , nil }
CreateContentObject creates a content object from the given payload.
CreateContentObject creates a content object from the given payload .
//nolint:lll