package functions

import (
	"github.com/google/uuid"
	"htwkalender/data-manager/model"
)

// generateUUIDs generates a UUID for each event based on the event name, course and semester
// the UUID is used to identify the event in the database
func GenerateUUIDs(events []model.Event) []model.Event {
	for i, event := range events {
		// generate a hash value from the event name, course and semester
		hash := GenerateUUID(event)
		events[i].UUID = hash
	}
	return events
}

func GenerateUUID(event model.Event) string {
	hash := uuid.NewSHA1(uuid.NameSpaceOID, []byte(event.Name+event.Course)).String()
	return hash
}
