package v1

const (
	primaryNotificationLarkUserID = "a851fd18"
	primaryNotificationLarkOpenID = "ou_c741c85928a0dcf2517bac9efa9591fd"
	downloadInitialLarkUserID     = "897a1cg1"
)

func initialDownloadCollaborators() []string {
	return []string{downloadInitialLarkUserID}
}

func escalatedDownloadCollaborators() []string {
	return []string{primaryNotificationLarkUserID, downloadInitialLarkUserID}
}

func firstDownloadAlertRecipients(downloader string) (string, []string) {
	return downloader, uniqueCollaborators(downloader, initialDownloadCollaborators()...)
}

func escalatedDownloadAlertRecipients(manager string) (string, []string) {
	return manager, uniqueCollaborators(manager, escalatedDownloadCollaborators()...)
}

// uniqueCollaborators returns non-empty collaborators in their original order,
// excluding the responsible person and repeated recipients.
func uniqueCollaborators(responsible string, candidates ...string) []string {
	seen := make(map[string]struct{}, len(candidates)+1)
	if responsible != "" {
		seen[responsible] = struct{}{}
	}

	result := make([]string, 0, len(candidates))
	for _, candidate := range candidates {
		if candidate == "" {
			continue
		}
		if _, exists := seen[candidate]; exists {
			continue
		}
		seen[candidate] = struct{}{}
		result = append(result, candidate)
	}

	return result
}
