tenseleyflow/shithub / d3a03d3

Browse files

billing: SubjectKind type + Org/User constants

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
d3a03d3e10f988a0d9e009d638243afad7fb3a46
Parents
11bf3d9
Tree
3fd4195

1 changed file

StatusFile+-
A internal/billing/subject.go 41 0
internal/billing/subject.goadded
@@ -0,0 +1,41 @@
1
+// SPDX-License-Identifier: AGPL-3.0-or-later
2
+
3
+package billing
4
+
5
+// SubjectKind discriminates which side of the polymorphic billing
6
+// schema a row applies to. Mirrors the `billing_subject_kind` enum
7
+// from migration 0074.
8
+//
9
+// PRO02 Q1 ratified the hybrid table strategy: `billing_invoices`
10
+// and `billing_webhook_events` carry `(subject_kind, subject_id)`;
11
+// `org_billing_states` and `user_billing_states` remain
12
+// kind-specific. Go callers that need to thread the kind through
13
+// (webhook routing, polymorphic invoice queries) use the constants
14
+// below.
15
+//
16
+// PRO04 builds the `Principal{Kind, ID}` abstraction on top of
17
+// these; PRO03 ships the constants alone so the queries it adds in
18
+// billing.sql have a typed Go binding without yet depending on
19
+// PRO04's larger Principal refactor.
20
+type SubjectKind string
21
+
22
+const (
23
+	SubjectKindUser SubjectKind = "user"
24
+	SubjectKindOrg  SubjectKind = "org"
25
+)
26
+
27
+// String satisfies fmt.Stringer for log fields without forcing
28
+// callers to cast.
29
+func (k SubjectKind) String() string { return string(k) }
30
+
31
+// Valid reports whether the kind is one of the known enum values.
32
+// Used at sqlc-binding sites to guard against zero-value bugs
33
+// before they reach the database (which would surface as a clearer
34
+// but later "invalid input value for enum" error).
35
+func (k SubjectKind) Valid() bool {
36
+	switch k {
37
+	case SubjectKindUser, SubjectKindOrg:
38
+		return true
39
+	}
40
+	return false
41
+}