package invite import ( "context" "fmt" "time" "tug/internal/storage" ) type Issued struct { ID string Label string URL string ExpiresAt time.Time } func (s *Service) CreateMany(ctx context.Context, createdBy string, labels, groupIDs []string, validFor time.Duration) ([]Issued, error) { input := storage.CreateInvitationsInput{GroupIDs: groupIDs, CreatedBy: createdBy, ValidFor: validFor, AdminGroup: s.cfg.AdminGroup} tokens := make([]string, 0, len(labels)) for _, label := range labels { token, hash, err := newToken() if err != nil { return nil, err } tokens = append(tokens, token) input.Invitations = append(input.Invitations, storage.NewInvitation{TokenHash: hash, Label: label}) } records, err := s.store.CreateInvitationsAudited(ctx, input) if err != nil { return nil, fmt.Errorf("invite: create invitations: %w", err) } issued := make([]Issued, 0, len(records)) for i, r := range records { issued = append(issued, Issued{ID: r.ID, Label: r.Label, URL: s.url(tokens[i]), ExpiresAt: r.ExpiresAt}) } return issued, nil }