export type CommunityGoalScaledUnits = string; interface CommunityGoalMutationEnvelope { moduleId: "helyx.community-goals"; operationKey: string; guildId: string; actorUserId: string | null; occurredAt: Date; } export type CommunityGoalMutationRequest = CommunityGoalMutationEnvelope & ({ kind: "create_goal"; goalId: string; draft: Readonly>; } | { kind: "update_goal"; goalId: string; expectedRevision: number; patch: Readonly>; namedConfirmation?: string; } | { kind: "publish_goal"; goalId: string; expectedRevision: number; now: Date; } | { kind: "transition_goal"; goalId: string; expectedRevision: number; expectedScheduleRevision?: number; targetStatus: "active" | "paused" | "completed" | "archived" | "deleted"; reason: string; } | { kind: "submit"; goalId: string; memberId: string; memberRoleIds: readonly string[]; amountScaled: CommunityGoalScaledUnits; expectedGoalRevision: number; expectedPeriod: number; expectedRuleRevision: number; } | { kind: "review_submission"; goalId: string; submissionId: string; expectedGoalRevision: number; expectedSubmissionRevision: number; expectedPeriod: number; decision: "approve" | "reject"; } | { kind: "withdraw_submission"; goalId: string; submissionId: string; memberId: string; expectedSubmissionRevision: number; } | { kind: "request_removal"; goalId: string; submissionId: string; memberId: string; expectedSubmissionRevision: number; } | { kind: "decide_removal"; goalId: string; submissionId: string; requestId: string; expectedGoalRevision: number; expectedSubmissionRevision: number; expectedRequestRevision: number; decision: "approve" | "deny"; } | { kind: "reset"; goalId: string; expectedRevision: number; expectedPeriod: number; mode: "retain_history" | "void_current"; } | { kind: "adjust"; goalId: string; adjustmentId: string; expectedRevision: number; expectedPeriod: number; action: "create" | "void"; amountScaled?: CommunityGoalScaledUnits; privateReason?: string; } | { kind: "delete_or_archive"; goalId: string; expectedRevision: number; action: "archive" | "delete"; } | { kind: "mark_resource_repair"; goalId: string; resourceKind: "goal_post" | "leaderboard" | "role"; resourceId: string; safeReason: string; }); export type CommunityGoalMutationRejectionCode = "not_found" | "stale_revision" | "stale_period" | "invalid_transition" | "quota_exceeded" | "history_cleanup_failed" | "not_active" | "outside_schedule" | "ineligible" | "limit_exceeded" | "spillover_conflict" | "state_conflict" | "ownership_mismatch" | "operation_key_conflict"; export type CommunityGoalMutationResult = { outcome: "committed"; replayed: boolean; goalId: string; goalRevision: number; periodNumber: number; status: string; projectedUnits: CommunityGoalScaledUnits; submissionId?: string; submissionState?: string; adjustmentId?: string; crossedMilestoneIds: readonly string[]; purgedGoalIds: readonly string[]; } | { outcome: "rejected"; code: CommunityGoalMutationRejectionCode; remainingUnits?: CommunityGoalScaledUnits; }; export interface CommunityGoalProjection { guildId: string; goalId: string; periodNumber: number; goalRevision: number; status: string; approvedSubmissionUnits: CommunityGoalScaledUnits; adjustmentUnits: CommunityGoalScaledUnits; projectedUnits: CommunityGoalScaledUnits; participantCount: number; } export type CommunityGoalLeaderboardQuery = { kind: "goal"; guildId: string; goalId: string; periodNumber: number; cursor?: string; limit: number; } | { kind: "participated" | "submissions"; guildId: string; cursor?: string; limit: number; }; export interface CommunityGoalLeaderboardItem { rank: number; memberId: string; amountScaled?: CommunityGoalScaledUnits; count?: number; reachedAt?: string; } export type CommunityGoalDeliveryKind = "goal_post" | "goal_leaderboard" | "overall_participated" | "overall_submissions" | "milestone" | "completion" | "delete_message"; export interface CommunityGoalDeliveryWork { deliveryId: string; generation: string; kind: CommunityGoalDeliveryKind; guildId: string; goalId: string | null; sourceId: string; channelId: string; messageId: string | null; messageChannelId: string | null; messageTemplate: string | null; periodNumber: number | null; attemptCount: number; } export interface CommunityGoalProgressService { mutate(input: CommunityGoalMutationRequest): Promise; reconcile(input: { guildId: string; operationKey: string; now: Date; maximum: number; resourceEvent?: { kind: "message_deleted" | "channel_deleted" | "channel_updated" | "role_deleted" | "role_updated"; resourceId: string; }; }): Promise<{ processed: number; goalIds: readonly string[]; reviewRequired: boolean; }>; eraseSubject(input: { requestId: string; discordUserId: string; cutoff: Date; operationKey: string; cursor?: string; }): Promise<{ processed: number; nextCursor?: string; residualCount: number; reviewRequired: boolean; }>; checkInvariant(input: { guildId: string; goalId: string; repair: boolean; actorUserId: string | null; operationKey: string; }): Promise<{ expectedUnits: CommunityGoalScaledUnits; actualUnits: CommunityGoalScaledUnits; repaired: boolean; goalRevision: number; }>; readProjection(input: { guildId: string; goalId: string; periodNumber?: number; }): Promise; listLeaderboard(input: CommunityGoalLeaderboardQuery): Promise<{ items: readonly CommunityGoalLeaderboardItem[]; nextCursor?: string; }>; claimDeliveryWork(input: { guildId?: string; owner: string; now: Date; maximum: number; leaseMs: number; }): Promise; completeDeliveryWork(input: { deliveryId: string; owner: string; generation: string; now: Date; outcome: "delivered" | "retry" | "review"; messageId?: string; safeCode?: string; delayMs?: number; }): Promise<{ superseded: boolean; reviewRequired: boolean; }>; } export {};