package test import ( "fmt" "math/rand" "time" "git.anthrove.art/Anthrove/otter-space-sdk/v5/pkg/models" "github.com/davecgh/go-spew/spew" gonanoid "github.com/matoous/go-nanoid/v2" "gorm.io/gorm" ) func GenerateRandomTags(num int) []models.Tag { var tags []models.Tag tagTypes := []models.TagType{"general", "species", "character", "artist", "lore", "meta", "invalid", "copyright"} for i := 0; i < num; i++ { id, _ := gonanoid.New(10) tagName := spew.Sprintf("tag_name_%s", id) tagType := tagTypes[rand.Intn(len(tagTypes))] tag := models.Tag{ Name: models.TagName(tagName), Type: tagType, } tags = append(tags, tag) } return tags } func GenerateRandomTagGroups(tags []models.Tag, num int) []models.TagGroup { var tagGroups []models.TagGroup for i := 0; i < num; i++ { id, _ := gonanoid.New(10) groupName := fmt.Sprintf("tag_group_%s", id) randomTag := tags[rand.Intn(len(tags))] tagGroup := models.TagGroup{ Name: models.TagGroupName(groupName), TagID: randomTag.Name, } tagGroups = append(tagGroups, tagGroup) } return tagGroups } func GenerateRandomTagAlias(tags []models.Tag, num int) []models.TagAlias { var tagAliases []models.TagAlias for i := 0; i < num; i++ { id, _ := gonanoid.New(10) groupName := fmt.Sprintf("tag_alias_%s", id) randomTag := tags[rand.Intn(len(tags))] tagAlias := models.TagAlias{ Name: models.TagAliasName(groupName), TagID: randomTag.Name, } tagAliases = append(tagAliases, tagAlias) } return tagAliases } func GenerateRandomSources(num int) []models.Source { var sources []models.Source for i := 0; i < num; i++ { id, _ := gonanoid.New(10) displayName, _ := gonanoid.New(10) domain, _ := gonanoid.New(10) icon, _ := gonanoid.New(10) id = spew.Sprintf("source_name_%s", id) source := models.Source{ BaseModel: models.BaseModel[models.SourceID]{ ID: models.SourceID(id), CreatedAt: time.Now(), UpdatedAt: time.Now(), DeletedAt: gorm.DeletedAt{}, }, DisplayName: displayName, Domain: models.SourceDomain(domain), Icon: icon, UserSources: nil, References: nil, } sources = append(sources, source) } return sources } func GenerateRandomPosts(num int) []models.Post { var sources []models.Post ratings := []models.Rating{"safe", "explicit", "questionable", "unknown"} for i := 0; i < num; i++ { id, _ := gonanoid.New(10) id = spew.Sprintf("source_name_%s", id) rating := ratings[rand.Intn(len(ratings))] source := models.Post{ BaseModel: models.BaseModel[models.PostID]{ ID: models.PostID(id), CreatedAt: time.Now(), UpdatedAt: time.Now(), DeletedAt: gorm.DeletedAt{}, }, Rating: rating, } sources = append(sources, source) } return sources } func GenerateRandomUserFavorites(userID models.UserID, postID models.PostID, userSourceID models.UserSourceID, num int) []models.UserFavorite { var userFavorites []models.UserFavorite for i := 0; i < num; i++ { id, _ := gonanoid.New(6) id = spew.Sprintf("user_favorite_name_%s", id) source := models.UserFavorite{ BaseModel: models.BaseModel[models.UserFavoriteID]{ ID: models.UserFavoriteID(id), CreatedAt: time.Now(), UpdatedAt: time.Now(), DeletedAt: gorm.DeletedAt{}, }, UserID: userID, PostID: postID, UserSourceID: userSourceID, } userFavorites = append(userFavorites, source) } return userFavorites }