diff --git a/contrib/claude/coredata.md b/contrib/claude/coredata.md index ade2e7d2f..fdb3b4ed2 100644 --- a/contrib/claude/coredata.md +++ b/contrib/claude/coredata.md @@ -297,17 +297,89 @@ func (f *CookieBannerFilter) SQLArguments() pgx.StrictNamedArgs { For complex multi-field filters, use `CASE WHEN` in SQL and always declare all argument keys in every code path (use `nil` for inactive ones). -## Order fields +## Enums -String-based enums with `Column()`, `IsValid()`, `String()`, and `MarshalText`/`UnmarshalText`: +Coredata enums are always `type X string` with a single validation source of truth (`IsValid`) and text marshalling support for pgx/JSON wiring. ```go -type AssetOrderField string +type XXXType string const ( - AssetOrderFieldCreatedAt AssetOrderField = "CREATED_AT" - AssetOrderFieldName AssetOrderField = "NAME" + XXXTypeAlpha XXXType = "ALPHA" + XXXTypeBeta XXXType = "BETA" ) + +var ( + _ fmt.Stringer = XXXType("") + _ encoding.TextMarshaler = XXXType("") + _ encoding.TextUnmarshaler = (*XXXType)(nil) +) + +func XXXTypes() []XXXType { + return []XXXType{ + XXXTypeAlpha, + XXXTypeBeta, + } +} + +func (v XXXType) IsValid() bool { + switch v { + case XXXTypeAlpha, XXXTypeBeta: + return true + } + + return false +} + +func (v XXXType) String() string { return string(v) } + +func (v XXXType) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *XXXType) UnmarshalText(text []byte) error { + val := XXXType(text) + if !val.IsValid() { + return fmt.Errorf("invalid XXXType value: %q", string(text)) + } + + *v = val + return nil +} +``` + +Rules: + +- Keep enums as string types only (no iota/int enums). +- `UnmarshalText` must validate via `IsValid`; do not duplicate validation switches in `Scan`/`Value`. +- Do not implement `database/sql` `Scan`/`Value` on singular enums in coredata; pgx uses `MarshalText` / `UnmarshalText`. +- Add compile-time interface checks in a `var` block for every enum (`fmt.Stringer`, `encoding.TextMarshaler`, `encoding.TextUnmarshaler`). +- Keep a `Values()` helper named as the pluralized enum type when there is no naming conflict. + +Collection enum wrappers (`OAuth2Scopes`, `CountryCodes`, etc.) may keep custom parsing/encoding methods when wire format differs from a single enum token. + +## Order fields + +Order-field enums follow the same enum rules and additionally implement `Column()` and `page.OrderField`: + +```go +type XXXOrderField string + +const ( + XXXOrderFieldCreatedAt XXXOrderField = "CREATED_AT" + XXXOrderFieldName XXXOrderField = "NAME" +) + +var ( + _ page.OrderField = XXXOrderField("") + _ fmt.Stringer = XXXOrderField("") + _ encoding.TextMarshaler = XXXOrderField("") + _ encoding.TextUnmarshaler = (*XXXOrderField)(nil) +) + +func (f XXXOrderField) Column() string { + return string(f) +} ``` Each entity implements `CursorKey(field)` returning `page.NewCursorKey(entity.ID, sortValue)`, with a `panic` on unknown fields. diff --git a/pkg/coredata/access_entry_account_type.go b/pkg/coredata/access_entry_account_type.go index 17972d0d4..6c59a678c 100644 --- a/pkg/coredata/access_entry_account_type.go +++ b/pkg/coredata/access_entry_account_type.go @@ -15,7 +15,7 @@ package coredata import ( - "database/sql/driver" + "encoding" "fmt" ) @@ -26,6 +26,12 @@ const ( AccessEntryAccountTypeServiceAccount AccessEntryAccountType = "SERVICE_ACCOUNT" ) +var ( + _ fmt.Stringer = AccessEntryAccountType("") + _ encoding.TextMarshaler = AccessEntryAccountType("") + _ encoding.TextUnmarshaler = (*AccessEntryAccountType)(nil) +) + func AccessEntryAccountTypes() []AccessEntryAccountType { return []AccessEntryAccountType{ AccessEntryAccountTypeUser, @@ -33,34 +39,32 @@ func AccessEntryAccountTypes() []AccessEntryAccountType { } } -func (a AccessEntryAccountType) String() string { - return string(a) +func (v AccessEntryAccountType) IsValid() bool { + switch v { + case + AccessEntryAccountTypeUser, + AccessEntryAccountTypeServiceAccount: + return true + } + + return false } -func (a *AccessEntryAccountType) Scan(value any) error { - var str string +func (v AccessEntryAccountType) String() string { + return string(v) +} - switch v := value.(type) { - case string: - str = v - case []byte: - str = string(v) - default: - return fmt.Errorf("cannot scan AccessEntryAccountType: unsupported type %T", value) +func (v AccessEntryAccountType) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *AccessEntryAccountType) UnmarshalText(text []byte) error { + val := AccessEntryAccountType(text) + if !val.IsValid() { + return fmt.Errorf("invalid AccessEntryAccountType value: %q", string(text)) } - switch str { - case "USER": - *a = AccessEntryAccountTypeUser - case "SERVICE_ACCOUNT": - *a = AccessEntryAccountTypeServiceAccount - default: - return fmt.Errorf("cannot parse AccessEntryAccountType: invalid value %q", str) - } + *v = val return nil } - -func (a AccessEntryAccountType) Value() (driver.Value, error) { - return a.String(), nil -} diff --git a/pkg/coredata/access_entry_account_type_test.go b/pkg/coredata/access_entry_account_type_test.go index e3664f87b..b4e22b304 100644 --- a/pkg/coredata/access_entry_account_type_test.go +++ b/pkg/coredata/access_entry_account_type_test.go @@ -16,56 +16,63 @@ package coredata import "testing" -func TestAccessEntryAccountTypeScan(t *testing.T) { +func TestAccessEntryAccountTypeIsValid(t *testing.T) { t.Parallel() - tests := []struct { - name string - input any - want AccessEntryAccountType - wantErr bool - }{ - {name: "user string", input: "USER", want: AccessEntryAccountTypeUser}, - {name: "service_account bytes", input: []byte("SERVICE_ACCOUNT"), want: AccessEntryAccountTypeServiceAccount}, - {name: "invalid value", input: "BOGUS", wantErr: true}, - {name: "unsupported type", input: 42, wantErr: true}, + for _, value := range AccessEntryAccountTypes() { + if !value.IsValid() { + t.Fatalf("IsValid() = false for %q", value) + } } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { + if AccessEntryAccountType("BOGUS").IsValid() { + t.Fatal("IsValid() = true for invalid value") + } +} + +func TestAccessEntryAccountTypeUnmarshalText(t *testing.T) { + t.Parallel() + + for _, value := range AccessEntryAccountTypes() { + t.Run(string(value), func(t *testing.T) { t.Parallel() var got AccessEntryAccountType - - err := got.Scan(tt.input) - if tt.wantErr { - if err == nil { - t.Fatalf("Scan(%v) expected error", tt.input) - } - - return + if err := got.UnmarshalText([]byte(value)); err != nil { + t.Fatalf("UnmarshalText(%q) returned error: %v", value, err) } + if got != value { + t.Fatalf("UnmarshalText(%q) = %q, want %q", value, got, value) + } + }) + } + + t.Run("invalid", func(t *testing.T) { + t.Parallel() + + var got AccessEntryAccountType + if err := got.UnmarshalText([]byte("BOGUS")); err == nil { + t.Fatal("UnmarshalText(BOGUS) expected error") + } + }) +} + +func TestAccessEntryAccountTypeMarshalText(t *testing.T) { + t.Parallel() + + for _, value := range AccessEntryAccountTypes() { + t.Run(string(value), func(t *testing.T) { + t.Parallel() + + got, err := value.MarshalText() if err != nil { - t.Fatalf("Scan(%v) returned error: %v", tt.input, err) + t.Fatalf("MarshalText() returned error: %v", err) } - if got != tt.want { - t.Fatalf("Scan(%v) = %q, want %q", tt.input, got, tt.want) + if string(got) != value.String() { + t.Fatalf("MarshalText() = %q, want %q", string(got), value.String()) } }) } } - -func TestAccessEntryAccountTypeValue(t *testing.T) { - t.Parallel() - - got, err := AccessEntryAccountTypeUser.Value() - if err != nil { - t.Fatalf("Value() returned error: %v", err) - } - - if got != "USER" { - t.Fatalf("Value() = %q, want %q", got, "USER") - } -} diff --git a/pkg/coredata/access_entry_decision.go b/pkg/coredata/access_entry_decision.go index 8afc94642..4e714dfea 100644 --- a/pkg/coredata/access_entry_decision.go +++ b/pkg/coredata/access_entry_decision.go @@ -15,7 +15,7 @@ package coredata import ( - "database/sql/driver" + "encoding" "fmt" ) @@ -29,40 +29,51 @@ const ( AccessEntryDecisionEscalate AccessEntryDecision = "ESCALATE" ) -func (d AccessEntryDecision) String() string { - return string(d) +var ( + _ fmt.Stringer = AccessEntryDecision("") + _ encoding.TextMarshaler = AccessEntryDecision("") + _ encoding.TextUnmarshaler = (*AccessEntryDecision)(nil) +) + +func AccessEntryDecisions() []AccessEntryDecision { + return []AccessEntryDecision{ + AccessEntryDecisionPending, + AccessEntryDecisionApproved, + AccessEntryDecisionRevoke, + AccessEntryDecisionDefer, + AccessEntryDecisionEscalate, + } } -func (d *AccessEntryDecision) Scan(value any) error { - var str string - - switch v := value.(type) { - case string: - str = v - case []byte: - str = string(v) - default: - return fmt.Errorf("cannot scan AccessEntryDecision: unsupported type %T", value) +func (v AccessEntryDecision) IsValid() bool { + switch v { + case + AccessEntryDecisionPending, + AccessEntryDecisionApproved, + AccessEntryDecisionRevoke, + AccessEntryDecisionDefer, + AccessEntryDecisionEscalate: + return true } - switch str { - case "PENDING": - *d = AccessEntryDecisionPending - case "APPROVED": - *d = AccessEntryDecisionApproved - case "REVOKE": - *d = AccessEntryDecisionRevoke - case "DEFER": - *d = AccessEntryDecisionDefer - case "ESCALATE": - *d = AccessEntryDecisionEscalate - default: - return fmt.Errorf("cannot parse AccessEntryDecision: invalid value %q", str) + return false +} + +func (v AccessEntryDecision) String() string { + return string(v) +} + +func (v AccessEntryDecision) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *AccessEntryDecision) UnmarshalText(text []byte) error { + val := AccessEntryDecision(text) + if !val.IsValid() { + return fmt.Errorf("invalid AccessEntryDecision value: %q", string(text)) } + *v = val + return nil } - -func (d AccessEntryDecision) Value() (driver.Value, error) { - return d.String(), nil -} diff --git a/pkg/coredata/access_entry_decision_test.go b/pkg/coredata/access_entry_decision_test.go index 1a7bc560c..6785f6623 100644 --- a/pkg/coredata/access_entry_decision_test.go +++ b/pkg/coredata/access_entry_decision_test.go @@ -16,74 +16,62 @@ package coredata import "testing" -func TestAccessEntryDecisionScan(t *testing.T) { +func TestAccessEntryDecisionIsValid(t *testing.T) { t.Parallel() - tests := []struct { - name string - input any - want AccessEntryDecision - wantErr bool - }{ - {name: "pending string", input: "PENDING", want: AccessEntryDecisionPending}, - {name: "approved string", input: "APPROVED", want: AccessEntryDecisionApproved}, - {name: "revoke string", input: "REVOKE", want: AccessEntryDecisionRevoke}, - {name: "defer bytes", input: []byte("DEFER"), want: AccessEntryDecisionDefer}, - {name: "escalate string", input: "ESCALATE", want: AccessEntryDecisionEscalate}, - {name: "invalid value", input: "BOGUS", wantErr: true}, - {name: "unsupported type", input: 42, wantErr: true}, + for _, value := range AccessEntryDecisions() { + if !value.IsValid() { + t.Fatalf("IsValid() = false for %q", value) + } } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { + if AccessEntryDecision("BOGUS").IsValid() { + t.Fatal("IsValid() = true for invalid value") + } +} + +func TestAccessEntryDecisionUnmarshalText(t *testing.T) { + t.Parallel() + + for _, value := range AccessEntryDecisions() { + t.Run(string(value), func(t *testing.T) { t.Parallel() var got AccessEntryDecision - - err := got.Scan(tt.input) - if tt.wantErr { - if err == nil { - t.Fatalf("Scan(%v) expected error", tt.input) - } - - return + if err := got.UnmarshalText([]byte(value)); err != nil { + t.Fatalf("UnmarshalText(%q) returned error: %v", value, err) } - if err != nil { - t.Fatalf("Scan(%v) returned error: %v", tt.input, err) - } - - if got != tt.want { - t.Fatalf("Scan(%v) = %q, want %q", tt.input, got, tt.want) + if got != value { + t.Fatalf("UnmarshalText(%q) = %q, want %q", value, got, value) } }) } + + t.Run("invalid", func(t *testing.T) { + t.Parallel() + + var got AccessEntryDecision + if err := got.UnmarshalText([]byte("BOGUS")); err == nil { + t.Fatal("UnmarshalText(BOGUS) expected error") + } + }) } -func TestAccessEntryDecisionValue(t *testing.T) { +func TestAccessEntryDecisionMarshalText(t *testing.T) { t.Parallel() - tests := []struct { - name string - decision AccessEntryDecision - want string - }{ - {name: "pending", decision: AccessEntryDecisionPending, want: "PENDING"}, - {name: "approved", decision: AccessEntryDecisionApproved, want: "APPROVED"}, - {name: "revoke", decision: AccessEntryDecisionRevoke, want: "REVOKE"}, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { + for _, value := range AccessEntryDecisions() { + t.Run(string(value), func(t *testing.T) { t.Parallel() - got, err := tt.decision.Value() + got, err := value.MarshalText() if err != nil { - t.Fatalf("Value() returned error: %v", err) + t.Fatalf("MarshalText() returned error: %v", err) } - if got != tt.want { - t.Fatalf("Value() = %q, want %q", got, tt.want) + if string(got) != value.String() { + t.Fatalf("MarshalText() = %q, want %q", string(got), value.String()) } }) } diff --git a/pkg/coredata/access_entry_flag.go b/pkg/coredata/access_entry_flag.go index 1404d7ee8..d6848a191 100644 --- a/pkg/coredata/access_entry_flag.go +++ b/pkg/coredata/access_entry_flag.go @@ -15,7 +15,7 @@ package coredata import ( - "database/sql/driver" + "encoding" "fmt" ) @@ -39,60 +39,71 @@ const ( AccessEntryFlagSharedAccount AccessEntryFlag = "SHARED_ACCOUNT" ) -func (f AccessEntryFlag) String() string { - return string(f) +var ( + _ fmt.Stringer = AccessEntryFlag("") + _ encoding.TextMarshaler = AccessEntryFlag("") + _ encoding.TextUnmarshaler = (*AccessEntryFlag)(nil) +) + +func AccessEntryFlags() []AccessEntryFlag { + return []AccessEntryFlag{ + AccessEntryFlagNone, + AccessEntryFlagOrphaned, + AccessEntryFlagInactive, + AccessEntryFlagExcessive, + AccessEntryFlagRoleMismatch, + AccessEntryFlagNew, + AccessEntryFlagDormant, + AccessEntryFlagTerminatedUser, + AccessEntryFlagContractorExpired, + AccessEntryFlagSoDConflict, + AccessEntryFlagPrivilegedAccess, + AccessEntryFlagRoleCreep, + AccessEntryFlagNoBusinessJustification, + AccessEntryFlagOutOfDepartment, + AccessEntryFlagSharedAccount, + } } -func (f *AccessEntryFlag) Scan(value any) error { - var str string - - switch v := value.(type) { - case string: - str = v - case []byte: - str = string(v) - default: - return fmt.Errorf("cannot scan AccessEntryFlag: unsupported type %T", value) +func (v AccessEntryFlag) IsValid() bool { + switch v { + case + AccessEntryFlagNone, + AccessEntryFlagOrphaned, + AccessEntryFlagInactive, + AccessEntryFlagExcessive, + AccessEntryFlagRoleMismatch, + AccessEntryFlagNew, + AccessEntryFlagDormant, + AccessEntryFlagTerminatedUser, + AccessEntryFlagContractorExpired, + AccessEntryFlagSoDConflict, + AccessEntryFlagPrivilegedAccess, + AccessEntryFlagRoleCreep, + AccessEntryFlagNoBusinessJustification, + AccessEntryFlagOutOfDepartment, + AccessEntryFlagSharedAccount: + return true } - switch str { - case "NONE": - *f = AccessEntryFlagNone - case "ORPHANED": - *f = AccessEntryFlagOrphaned - case "INACTIVE": - *f = AccessEntryFlagInactive - case "EXCESSIVE": - *f = AccessEntryFlagExcessive - case "ROLE_MISMATCH": - *f = AccessEntryFlagRoleMismatch - case "NEW": - *f = AccessEntryFlagNew - case "DORMANT": - *f = AccessEntryFlagDormant - case "TERMINATED_USER": - *f = AccessEntryFlagTerminatedUser - case "CONTRACTOR_EXPIRED": - *f = AccessEntryFlagContractorExpired - case "SOD_CONFLICT": - *f = AccessEntryFlagSoDConflict - case "PRIVILEGED_ACCESS": - *f = AccessEntryFlagPrivilegedAccess - case "ROLE_CREEP": - *f = AccessEntryFlagRoleCreep - case "NO_BUSINESS_JUSTIFICATION": - *f = AccessEntryFlagNoBusinessJustification - case "OUT_OF_DEPARTMENT": - *f = AccessEntryFlagOutOfDepartment - case "SHARED_ACCOUNT": - *f = AccessEntryFlagSharedAccount - default: - return fmt.Errorf("cannot parse AccessEntryFlag: invalid value %q", str) + return false +} + +func (v AccessEntryFlag) String() string { + return string(v) +} + +func (v AccessEntryFlag) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *AccessEntryFlag) UnmarshalText(text []byte) error { + val := AccessEntryFlag(text) + if !val.IsValid() { + return fmt.Errorf("invalid AccessEntryFlag value: %q", string(text)) } + *v = val + return nil } - -func (f AccessEntryFlag) Value() (driver.Value, error) { - return f.String(), nil -} diff --git a/pkg/coredata/access_entry_flag_test.go b/pkg/coredata/access_entry_flag_test.go index 60662052d..9835c2d76 100644 --- a/pkg/coredata/access_entry_flag_test.go +++ b/pkg/coredata/access_entry_flag_test.go @@ -16,60 +16,63 @@ package coredata import "testing" -func TestAccessEntryFlagScan(t *testing.T) { +func TestAccessEntryFlagIsValid(t *testing.T) { t.Parallel() - tests := []struct { - name string - input any - want AccessEntryFlag - wantErr bool - }{ - {name: "none string", input: "NONE", want: AccessEntryFlagNone}, - {name: "orphaned string", input: "ORPHANED", want: AccessEntryFlagOrphaned}, - {name: "inactive string", input: "INACTIVE", want: AccessEntryFlagInactive}, - {name: "excessive string", input: "EXCESSIVE", want: AccessEntryFlagExcessive}, - {name: "role_mismatch bytes", input: []byte("ROLE_MISMATCH"), want: AccessEntryFlagRoleMismatch}, - {name: "new string", input: "NEW", want: AccessEntryFlagNew}, - {name: "invalid value", input: "BOGUS", wantErr: true}, - {name: "unsupported type", input: 42, wantErr: true}, + for _, value := range AccessEntryFlags() { + if !value.IsValid() { + t.Fatalf("IsValid() = false for %q", value) + } } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { + if AccessEntryFlag("BOGUS").IsValid() { + t.Fatal("IsValid() = true for invalid value") + } +} + +func TestAccessEntryFlagUnmarshalText(t *testing.T) { + t.Parallel() + + for _, value := range AccessEntryFlags() { + t.Run(string(value), func(t *testing.T) { t.Parallel() var got AccessEntryFlag - - err := got.Scan(tt.input) - if tt.wantErr { - if err == nil { - t.Fatalf("Scan(%v) expected error", tt.input) - } - - return + if err := got.UnmarshalText([]byte(value)); err != nil { + t.Fatalf("UnmarshalText(%q) returned error: %v", value, err) } + if got != value { + t.Fatalf("UnmarshalText(%q) = %q, want %q", value, got, value) + } + }) + } + + t.Run("invalid", func(t *testing.T) { + t.Parallel() + + var got AccessEntryFlag + if err := got.UnmarshalText([]byte("BOGUS")); err == nil { + t.Fatal("UnmarshalText(BOGUS) expected error") + } + }) +} + +func TestAccessEntryFlagMarshalText(t *testing.T) { + t.Parallel() + + for _, value := range AccessEntryFlags() { + t.Run(string(value), func(t *testing.T) { + t.Parallel() + + got, err := value.MarshalText() if err != nil { - t.Fatalf("Scan(%v) returned error: %v", tt.input, err) + t.Fatalf("MarshalText() returned error: %v", err) } - if got != tt.want { - t.Fatalf("Scan(%v) = %q, want %q", tt.input, got, tt.want) + if string(got) != value.String() { + t.Fatalf("MarshalText() = %q, want %q", string(got), value.String()) } }) } } - -func TestAccessEntryFlagValue(t *testing.T) { - t.Parallel() - - got, err := AccessEntryFlagNone.Value() - if err != nil { - t.Fatalf("Value() returned error: %v", err) - } - - if got != "NONE" { - t.Fatalf("Value() = %q, want %q", got, "NONE") - } -} diff --git a/pkg/coredata/access_entry_incremental_tag.go b/pkg/coredata/access_entry_incremental_tag.go index f3ba65701..7aa276e72 100644 --- a/pkg/coredata/access_entry_incremental_tag.go +++ b/pkg/coredata/access_entry_incremental_tag.go @@ -15,7 +15,7 @@ package coredata import ( - "database/sql/driver" + "encoding" "fmt" ) @@ -27,36 +27,47 @@ const ( AccessEntryIncrementalTagUnchanged AccessEntryIncrementalTag = "UNCHANGED" ) -func (t AccessEntryIncrementalTag) String() string { - return string(t) +var ( + _ fmt.Stringer = AccessEntryIncrementalTag("") + _ encoding.TextMarshaler = AccessEntryIncrementalTag("") + _ encoding.TextUnmarshaler = (*AccessEntryIncrementalTag)(nil) +) + +func AccessEntryIncrementalTags() []AccessEntryIncrementalTag { + return []AccessEntryIncrementalTag{ + AccessEntryIncrementalTagNew, + AccessEntryIncrementalTagRemoved, + AccessEntryIncrementalTagUnchanged, + } } -func (t *AccessEntryIncrementalTag) Scan(value any) error { - var str string - - switch v := value.(type) { - case string: - str = v - case []byte: - str = string(v) - default: - return fmt.Errorf("cannot scan AccessEntryIncrementalTag: unsupported type %T", value) +func (v AccessEntryIncrementalTag) IsValid() bool { + switch v { + case + AccessEntryIncrementalTagNew, + AccessEntryIncrementalTagRemoved, + AccessEntryIncrementalTagUnchanged: + return true } - switch str { - case "NEW": - *t = AccessEntryIncrementalTagNew - case "REMOVED": - *t = AccessEntryIncrementalTagRemoved - case "UNCHANGED": - *t = AccessEntryIncrementalTagUnchanged - default: - return fmt.Errorf("cannot parse AccessEntryIncrementalTag: invalid value %q", str) + return false +} + +func (v AccessEntryIncrementalTag) String() string { + return string(v) +} + +func (v AccessEntryIncrementalTag) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *AccessEntryIncrementalTag) UnmarshalText(text []byte) error { + val := AccessEntryIncrementalTag(text) + if !val.IsValid() { + return fmt.Errorf("invalid AccessEntryIncrementalTag value: %q", string(text)) } + *v = val + return nil } - -func (t AccessEntryIncrementalTag) Value() (driver.Value, error) { - return t.String(), nil -} diff --git a/pkg/coredata/access_entry_incremental_tag_test.go b/pkg/coredata/access_entry_incremental_tag_test.go index c91d8b71b..222120648 100644 --- a/pkg/coredata/access_entry_incremental_tag_test.go +++ b/pkg/coredata/access_entry_incremental_tag_test.go @@ -16,57 +16,63 @@ package coredata import "testing" -func TestAccessEntryIncrementalTagScan(t *testing.T) { +func TestAccessEntryIncrementalTagIsValid(t *testing.T) { t.Parallel() - tests := []struct { - name string - input any - want AccessEntryIncrementalTag - wantErr bool - }{ - {name: "new string", input: "NEW", want: AccessEntryIncrementalTagNew}, - {name: "removed bytes", input: []byte("REMOVED"), want: AccessEntryIncrementalTagRemoved}, - {name: "unchanged string", input: "UNCHANGED", want: AccessEntryIncrementalTagUnchanged}, - {name: "invalid value", input: "BOGUS", wantErr: true}, - {name: "unsupported type", input: 42, wantErr: true}, + for _, value := range AccessEntryIncrementalTags() { + if !value.IsValid() { + t.Fatalf("IsValid() = false for %q", value) + } } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { + if AccessEntryIncrementalTag("BOGUS").IsValid() { + t.Fatal("IsValid() = true for invalid value") + } +} + +func TestAccessEntryIncrementalTagUnmarshalText(t *testing.T) { + t.Parallel() + + for _, value := range AccessEntryIncrementalTags() { + t.Run(string(value), func(t *testing.T) { t.Parallel() var got AccessEntryIncrementalTag - - err := got.Scan(tt.input) - if tt.wantErr { - if err == nil { - t.Fatalf("Scan(%v) expected error", tt.input) - } - - return + if err := got.UnmarshalText([]byte(value)); err != nil { + t.Fatalf("UnmarshalText(%q) returned error: %v", value, err) } + if got != value { + t.Fatalf("UnmarshalText(%q) = %q, want %q", value, got, value) + } + }) + } + + t.Run("invalid", func(t *testing.T) { + t.Parallel() + + var got AccessEntryIncrementalTag + if err := got.UnmarshalText([]byte("BOGUS")); err == nil { + t.Fatal("UnmarshalText(BOGUS) expected error") + } + }) +} + +func TestAccessEntryIncrementalTagMarshalText(t *testing.T) { + t.Parallel() + + for _, value := range AccessEntryIncrementalTags() { + t.Run(string(value), func(t *testing.T) { + t.Parallel() + + got, err := value.MarshalText() if err != nil { - t.Fatalf("Scan(%v) returned error: %v", tt.input, err) + t.Fatalf("MarshalText() returned error: %v", err) } - if got != tt.want { - t.Fatalf("Scan(%v) = %q, want %q", tt.input, got, tt.want) + if string(got) != value.String() { + t.Fatalf("MarshalText() = %q, want %q", string(got), value.String()) } }) } } - -func TestAccessEntryIncrementalTagValue(t *testing.T) { - t.Parallel() - - got, err := AccessEntryIncrementalTagNew.Value() - if err != nil { - t.Fatalf("Value() returned error: %v", err) - } - - if got != "NEW" { - t.Fatalf("Value() = %q, want %q", got, "NEW") - } -} diff --git a/pkg/coredata/access_entry_order_field.go b/pkg/coredata/access_entry_order_field.go index d38282dc7..131749d87 100644 --- a/pkg/coredata/access_entry_order_field.go +++ b/pkg/coredata/access_entry_order_field.go @@ -14,7 +14,12 @@ package coredata -import "fmt" +import ( + "encoding" + "fmt" + + "go.probo.inc/probo/pkg/page" +) type ( AccessEntryOrderField string @@ -24,6 +29,48 @@ const ( AccessEntryOrderFieldCreatedAt AccessEntryOrderField = "CREATED_AT" ) +var ( + _ page.OrderField = AccessEntryOrderField("") + _ fmt.Stringer = AccessEntryOrderField("") + _ encoding.TextMarshaler = AccessEntryOrderField("") + _ encoding.TextUnmarshaler = (*AccessEntryOrderField)(nil) +) + +func AccessEntryOrderFields() []AccessEntryOrderField { + return []AccessEntryOrderField{ + AccessEntryOrderFieldCreatedAt, + } +} + +func (v AccessEntryOrderField) IsValid() bool { + switch v { + case + AccessEntryOrderFieldCreatedAt: + return true + } + + return false +} + +func (v AccessEntryOrderField) String() string { + return string(v) +} + +func (v AccessEntryOrderField) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *AccessEntryOrderField) UnmarshalText(text []byte) error { + val := AccessEntryOrderField(text) + if !val.IsValid() { + return fmt.Errorf("invalid AccessEntryOrderField value: %q", string(text)) + } + + *v = val + + return nil +} + func (p AccessEntryOrderField) Column() string { switch p { case AccessEntryOrderFieldCreatedAt: @@ -32,29 +79,3 @@ func (p AccessEntryOrderField) Column() string { panic(fmt.Sprintf("unsupported order by: %s", p)) } - -func (p AccessEntryOrderField) IsValid() bool { - switch p { - case AccessEntryOrderFieldCreatedAt: - return true - } - - return false -} - -func (p AccessEntryOrderField) String() string { - return string(p) -} - -func (p AccessEntryOrderField) MarshalText() ([]byte, error) { - return []byte(p.String()), nil -} - -func (p *AccessEntryOrderField) UnmarshalText(text []byte) error { - *p = AccessEntryOrderField(text) - if !p.IsValid() { - return fmt.Errorf("%s is not a valid AccessEntryOrderField", string(text)) - } - - return nil -} diff --git a/pkg/coredata/access_review_campaign_order_field.go b/pkg/coredata/access_review_campaign_order_field.go index 096e347f0..ec83f2a59 100644 --- a/pkg/coredata/access_review_campaign_order_field.go +++ b/pkg/coredata/access_review_campaign_order_field.go @@ -14,7 +14,12 @@ package coredata -import "fmt" +import ( + "encoding" + "fmt" + + "go.probo.inc/probo/pkg/page" +) type ( AccessReviewCampaignOrderField string @@ -24,6 +29,48 @@ const ( AccessReviewCampaignOrderFieldCreatedAt AccessReviewCampaignOrderField = "CREATED_AT" ) +var ( + _ page.OrderField = AccessReviewCampaignOrderField("") + _ fmt.Stringer = AccessReviewCampaignOrderField("") + _ encoding.TextMarshaler = AccessReviewCampaignOrderField("") + _ encoding.TextUnmarshaler = (*AccessReviewCampaignOrderField)(nil) +) + +func AccessReviewCampaignOrderFields() []AccessReviewCampaignOrderField { + return []AccessReviewCampaignOrderField{ + AccessReviewCampaignOrderFieldCreatedAt, + } +} + +func (v AccessReviewCampaignOrderField) IsValid() bool { + switch v { + case + AccessReviewCampaignOrderFieldCreatedAt: + return true + } + + return false +} + +func (v AccessReviewCampaignOrderField) String() string { + return string(v) +} + +func (v AccessReviewCampaignOrderField) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *AccessReviewCampaignOrderField) UnmarshalText(text []byte) error { + val := AccessReviewCampaignOrderField(text) + if !val.IsValid() { + return fmt.Errorf("invalid AccessReviewCampaignOrderField value: %q", string(text)) + } + + *v = val + + return nil +} + func (p AccessReviewCampaignOrderField) Column() string { switch p { case AccessReviewCampaignOrderFieldCreatedAt: @@ -32,29 +79,3 @@ func (p AccessReviewCampaignOrderField) Column() string { panic(fmt.Sprintf("unsupported order by: %s", p)) } - -func (p AccessReviewCampaignOrderField) IsValid() bool { - switch p { - case AccessReviewCampaignOrderFieldCreatedAt: - return true - } - - return false -} - -func (p AccessReviewCampaignOrderField) String() string { - return string(p) -} - -func (p AccessReviewCampaignOrderField) MarshalText() ([]byte, error) { - return []byte(p.String()), nil -} - -func (p *AccessReviewCampaignOrderField) UnmarshalText(text []byte) error { - *p = AccessReviewCampaignOrderField(text) - if !p.IsValid() { - return fmt.Errorf("%s is not a valid AccessReviewCampaignOrderField", string(text)) - } - - return nil -} diff --git a/pkg/coredata/access_review_campaign_source_fetch_status.go b/pkg/coredata/access_review_campaign_source_fetch_status.go index 68635f1d8..eed762dbb 100644 --- a/pkg/coredata/access_review_campaign_source_fetch_status.go +++ b/pkg/coredata/access_review_campaign_source_fetch_status.go @@ -15,7 +15,7 @@ package coredata import ( - "database/sql/driver" + "encoding" "fmt" ) @@ -28,42 +28,53 @@ const ( AccessReviewCampaignSourceFetchStatusFailed AccessReviewCampaignSourceFetchStatus = "FAILED" ) -func (s AccessReviewCampaignSourceFetchStatus) IsTerminal() bool { - return s == AccessReviewCampaignSourceFetchStatusSuccess || s == AccessReviewCampaignSourceFetchStatusFailed +var ( + _ fmt.Stringer = AccessReviewCampaignSourceFetchStatus("") + _ encoding.TextMarshaler = AccessReviewCampaignSourceFetchStatus("") + _ encoding.TextUnmarshaler = (*AccessReviewCampaignSourceFetchStatus)(nil) +) + +func AccessReviewCampaignSourceFetchStatuses() []AccessReviewCampaignSourceFetchStatus { + return []AccessReviewCampaignSourceFetchStatus{ + AccessReviewCampaignSourceFetchStatusQueued, + AccessReviewCampaignSourceFetchStatusFetching, + AccessReviewCampaignSourceFetchStatusSuccess, + AccessReviewCampaignSourceFetchStatusFailed, + } } -func (s AccessReviewCampaignSourceFetchStatus) String() string { - return string(s) +func (v AccessReviewCampaignSourceFetchStatus) IsValid() bool { + switch v { + case + AccessReviewCampaignSourceFetchStatusQueued, + AccessReviewCampaignSourceFetchStatusFetching, + AccessReviewCampaignSourceFetchStatusSuccess, + AccessReviewCampaignSourceFetchStatusFailed: + return true + } + + return false } -func (s *AccessReviewCampaignSourceFetchStatus) Scan(value any) error { - var str string +func (v AccessReviewCampaignSourceFetchStatus) String() string { + return string(v) +} - switch v := value.(type) { - case string: - str = v - case []byte: - str = string(v) - default: - return fmt.Errorf("cannot scan AccessReviewCampaignSourceFetchStatus: unsupported type %T", value) +func (v AccessReviewCampaignSourceFetchStatus) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *AccessReviewCampaignSourceFetchStatus) UnmarshalText(text []byte) error { + val := AccessReviewCampaignSourceFetchStatus(text) + if !val.IsValid() { + return fmt.Errorf("invalid AccessReviewCampaignSourceFetchStatus value: %q", string(text)) } - switch str { - case "QUEUED": - *s = AccessReviewCampaignSourceFetchStatusQueued - case "FETCHING": - *s = AccessReviewCampaignSourceFetchStatusFetching - case "SUCCESS": - *s = AccessReviewCampaignSourceFetchStatusSuccess - case "FAILED": - *s = AccessReviewCampaignSourceFetchStatusFailed - default: - return fmt.Errorf("cannot parse AccessReviewCampaignSourceFetchStatus: invalid value %q", str) - } + *v = val return nil } -func (s AccessReviewCampaignSourceFetchStatus) Value() (driver.Value, error) { - return s.String(), nil +func (s AccessReviewCampaignSourceFetchStatus) IsTerminal() bool { + return s == AccessReviewCampaignSourceFetchStatusSuccess || s == AccessReviewCampaignSourceFetchStatusFailed } diff --git a/pkg/coredata/access_review_campaign_source_fetch_status_test.go b/pkg/coredata/access_review_campaign_source_fetch_status_test.go index 31680f435..5cd2d5062 100644 --- a/pkg/coredata/access_review_campaign_source_fetch_status_test.go +++ b/pkg/coredata/access_review_campaign_source_fetch_status_test.go @@ -36,53 +36,62 @@ func TestAccessReviewCampaignSourceFetchStatusIsTerminal(t *testing.T) { } } -func TestAccessReviewCampaignSourceFetchStatusScan(t *testing.T) { +func TestAccessReviewCampaignSourceFetchStatusIsValid(t *testing.T) { t.Parallel() - tests := []struct { - name string - input any - want AccessReviewCampaignSourceFetchStatus - wantErr bool - }{ - { - name: "queued string", - input: "QUEUED", - want: AccessReviewCampaignSourceFetchStatusQueued, - }, - { - name: "fetching bytes", - input: []byte("FETCHING"), - want: AccessReviewCampaignSourceFetchStatusFetching, - }, - { - name: "invalid value", - input: "BOGUS", - wantErr: true, - }, + for _, value := range AccessReviewCampaignSourceFetchStatuses() { + if !value.IsValid() { + t.Fatalf("IsValid() = false for %q", value) + } } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { + if AccessReviewCampaignSourceFetchStatus("BOGUS").IsValid() { + t.Fatal("IsValid() = true for invalid value") + } +} + +func TestAccessReviewCampaignSourceFetchStatusUnmarshalText(t *testing.T) { + t.Parallel() + + for _, value := range AccessReviewCampaignSourceFetchStatuses() { + t.Run(string(value), func(t *testing.T) { t.Parallel() var got AccessReviewCampaignSourceFetchStatus - - err := got.Scan(tt.input) - if tt.wantErr { - if err == nil { - t.Fatalf("Scan(%v) expected error", tt.input) - } - - return + if err := got.UnmarshalText([]byte(value)); err != nil { + t.Fatalf("UnmarshalText(%q) returned error: %v", value, err) } + if got != value { + t.Fatalf("UnmarshalText(%q) = %q, want %q", value, got, value) + } + }) + } + + t.Run("invalid", func(t *testing.T) { + t.Parallel() + + var got AccessReviewCampaignSourceFetchStatus + if err := got.UnmarshalText([]byte("BOGUS")); err == nil { + t.Fatal("UnmarshalText(BOGUS) expected error") + } + }) +} + +func TestAccessReviewCampaignSourceFetchStatusMarshalText(t *testing.T) { + t.Parallel() + + for _, value := range AccessReviewCampaignSourceFetchStatuses() { + t.Run(string(value), func(t *testing.T) { + t.Parallel() + + got, err := value.MarshalText() if err != nil { - t.Fatalf("Scan(%v) returned error: %v", tt.input, err) + t.Fatalf("MarshalText() returned error: %v", err) } - if got != tt.want { - t.Fatalf("Scan(%v) = %q, want %q", tt.input, got, tt.want) + if string(got) != value.String() { + t.Fatalf("MarshalText() = %q, want %q", string(got), value.String()) } }) } diff --git a/pkg/coredata/access_review_campaign_status.go b/pkg/coredata/access_review_campaign_status.go index 267f90f66..6015238f6 100644 --- a/pkg/coredata/access_review_campaign_status.go +++ b/pkg/coredata/access_review_campaign_status.go @@ -15,7 +15,7 @@ package coredata import ( - "database/sql/driver" + "encoding" "fmt" ) @@ -29,40 +29,51 @@ const ( AccessReviewCampaignStatusCancelled AccessReviewCampaignStatus = "CANCELLED" ) -func (s AccessReviewCampaignStatus) String() string { - return string(s) +var ( + _ fmt.Stringer = AccessReviewCampaignStatus("") + _ encoding.TextMarshaler = AccessReviewCampaignStatus("") + _ encoding.TextUnmarshaler = (*AccessReviewCampaignStatus)(nil) +) + +func AccessReviewCampaignStatuses() []AccessReviewCampaignStatus { + return []AccessReviewCampaignStatus{ + AccessReviewCampaignStatusDraft, + AccessReviewCampaignStatusInProgress, + AccessReviewCampaignStatusPendingActions, + AccessReviewCampaignStatusCompleted, + AccessReviewCampaignStatusCancelled, + } } -func (s *AccessReviewCampaignStatus) Scan(value any) error { - var str string - - switch v := value.(type) { - case string: - str = v - case []byte: - str = string(v) - default: - return fmt.Errorf("cannot scan AccessReviewCampaignStatus: unsupported type %T", value) +func (v AccessReviewCampaignStatus) IsValid() bool { + switch v { + case + AccessReviewCampaignStatusDraft, + AccessReviewCampaignStatusInProgress, + AccessReviewCampaignStatusPendingActions, + AccessReviewCampaignStatusCompleted, + AccessReviewCampaignStatusCancelled: + return true } - switch str { - case "DRAFT": - *s = AccessReviewCampaignStatusDraft - case "IN_PROGRESS": - *s = AccessReviewCampaignStatusInProgress - case "PENDING_ACTIONS": - *s = AccessReviewCampaignStatusPendingActions - case "COMPLETED": - *s = AccessReviewCampaignStatusCompleted - case "CANCELLED": - *s = AccessReviewCampaignStatusCancelled - default: - return fmt.Errorf("cannot parse AccessReviewCampaignStatus: invalid value %q", str) + return false +} + +func (v AccessReviewCampaignStatus) String() string { + return string(v) +} + +func (v AccessReviewCampaignStatus) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *AccessReviewCampaignStatus) UnmarshalText(text []byte) error { + val := AccessReviewCampaignStatus(text) + if !val.IsValid() { + return fmt.Errorf("invalid AccessReviewCampaignStatus value: %q", string(text)) } + *v = val + return nil } - -func (s AccessReviewCampaignStatus) Value() (driver.Value, error) { - return s.String(), nil -} diff --git a/pkg/coredata/access_review_campaign_status_test.go b/pkg/coredata/access_review_campaign_status_test.go index 9db1d7ac9..b216bed98 100644 --- a/pkg/coredata/access_review_campaign_status_test.go +++ b/pkg/coredata/access_review_campaign_status_test.go @@ -16,74 +16,62 @@ package coredata import "testing" -func TestAccessReviewCampaignStatusScan(t *testing.T) { +func TestAccessReviewCampaignStatusIsValid(t *testing.T) { t.Parallel() - tests := []struct { - name string - input any - want AccessReviewCampaignStatus - wantErr bool - }{ - {name: "draft string", input: "DRAFT", want: AccessReviewCampaignStatusDraft}, - {name: "in_progress string", input: "IN_PROGRESS", want: AccessReviewCampaignStatusInProgress}, - {name: "pending_actions string", input: "PENDING_ACTIONS", want: AccessReviewCampaignStatusPendingActions}, - {name: "completed string", input: "COMPLETED", want: AccessReviewCampaignStatusCompleted}, - {name: "cancelled bytes", input: []byte("CANCELLED"), want: AccessReviewCampaignStatusCancelled}, - {name: "invalid value", input: "BOGUS", wantErr: true}, - {name: "unsupported type", input: 42, wantErr: true}, + for _, value := range AccessReviewCampaignStatuses() { + if !value.IsValid() { + t.Fatalf("IsValid() = false for %q", value) + } } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { + if AccessReviewCampaignStatus("BOGUS").IsValid() { + t.Fatal("IsValid() = true for invalid value") + } +} + +func TestAccessReviewCampaignStatusUnmarshalText(t *testing.T) { + t.Parallel() + + for _, value := range AccessReviewCampaignStatuses() { + t.Run(string(value), func(t *testing.T) { t.Parallel() var got AccessReviewCampaignStatus - - err := got.Scan(tt.input) - if tt.wantErr { - if err == nil { - t.Fatalf("Scan(%v) expected error", tt.input) - } - - return + if err := got.UnmarshalText([]byte(value)); err != nil { + t.Fatalf("UnmarshalText(%q) returned error: %v", value, err) } - if err != nil { - t.Fatalf("Scan(%v) returned error: %v", tt.input, err) - } - - if got != tt.want { - t.Fatalf("Scan(%v) = %q, want %q", tt.input, got, tt.want) + if got != value { + t.Fatalf("UnmarshalText(%q) = %q, want %q", value, got, value) } }) } + + t.Run("invalid", func(t *testing.T) { + t.Parallel() + + var got AccessReviewCampaignStatus + if err := got.UnmarshalText([]byte("BOGUS")); err == nil { + t.Fatal("UnmarshalText(BOGUS) expected error") + } + }) } -func TestAccessReviewCampaignStatusValue(t *testing.T) { +func TestAccessReviewCampaignStatusMarshalText(t *testing.T) { t.Parallel() - tests := []struct { - name string - status AccessReviewCampaignStatus - want string - }{ - {name: "draft", status: AccessReviewCampaignStatusDraft, want: "DRAFT"}, - {name: "in_progress", status: AccessReviewCampaignStatusInProgress, want: "IN_PROGRESS"}, - {name: "completed", status: AccessReviewCampaignStatusCompleted, want: "COMPLETED"}, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { + for _, value := range AccessReviewCampaignStatuses() { + t.Run(string(value), func(t *testing.T) { t.Parallel() - got, err := tt.status.Value() + got, err := value.MarshalText() if err != nil { - t.Fatalf("Value() returned error: %v", err) + t.Fatalf("MarshalText() returned error: %v", err) } - if got != tt.want { - t.Fatalf("Value() = %q, want %q", got, tt.want) + if string(got) != value.String() { + t.Fatalf("MarshalText() = %q, want %q", string(got), value.String()) } }) } diff --git a/pkg/coredata/access_source_category.go b/pkg/coredata/access_source_category.go index 9ff8ed5f6..dd8076cc9 100644 --- a/pkg/coredata/access_source_category.go +++ b/pkg/coredata/access_source_category.go @@ -15,7 +15,7 @@ package coredata import ( - "database/sql/driver" + "encoding" "fmt" ) @@ -28,6 +28,12 @@ const ( AccessSourceCategoryOther AccessSourceCategory = "OTHER" ) +var ( + _ fmt.Stringer = AccessSourceCategory("") + _ encoding.TextMarshaler = AccessSourceCategory("") + _ encoding.TextUnmarshaler = (*AccessSourceCategory)(nil) +) + func AccessSourceCategories() []AccessSourceCategory { return []AccessSourceCategory{ AccessSourceCategorySaaS, @@ -37,38 +43,34 @@ func AccessSourceCategories() []AccessSourceCategory { } } -func (c AccessSourceCategory) String() string { - return string(c) +func (v AccessSourceCategory) IsValid() bool { + switch v { + case + AccessSourceCategorySaaS, + AccessSourceCategoryCloudInfra, + AccessSourceCategorySourceCode, + AccessSourceCategoryOther: + return true + } + + return false } -func (c *AccessSourceCategory) Scan(value any) error { - var str string +func (v AccessSourceCategory) String() string { + return string(v) +} - switch v := value.(type) { - case string: - str = v - case []byte: - str = string(v) - default: - return fmt.Errorf("cannot scan AccessSourceCategory: unsupported type %T", value) +func (v AccessSourceCategory) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *AccessSourceCategory) UnmarshalText(text []byte) error { + val := AccessSourceCategory(text) + if !val.IsValid() { + return fmt.Errorf("invalid AccessSourceCategory value: %q", string(text)) } - switch str { - case "SAAS": - *c = AccessSourceCategorySaaS - case "CLOUD_INFRA": - *c = AccessSourceCategoryCloudInfra - case "SOURCE_CODE": - *c = AccessSourceCategorySourceCode - case "OTHER": - *c = AccessSourceCategoryOther - default: - return fmt.Errorf("cannot parse AccessSourceCategory: invalid value %q", str) - } + *v = val return nil } - -func (c AccessSourceCategory) Value() (driver.Value, error) { - return c.String(), nil -} diff --git a/pkg/coredata/access_source_category_test.go b/pkg/coredata/access_source_category_test.go index 13010e53c..0dc3580e9 100644 --- a/pkg/coredata/access_source_category_test.go +++ b/pkg/coredata/access_source_category_test.go @@ -16,58 +16,63 @@ package coredata import "testing" -func TestAccessSourceCategoryScan(t *testing.T) { +func TestAccessSourceCategoryIsValid(t *testing.T) { t.Parallel() - tests := []struct { - name string - input any - want AccessSourceCategory - wantErr bool - }{ - {name: "saas string", input: "SAAS", want: AccessSourceCategorySaaS}, - {name: "cloud_infra string", input: "CLOUD_INFRA", want: AccessSourceCategoryCloudInfra}, - {name: "source_code bytes", input: []byte("SOURCE_CODE"), want: AccessSourceCategorySourceCode}, - {name: "other string", input: "OTHER", want: AccessSourceCategoryOther}, - {name: "invalid value", input: "BOGUS", wantErr: true}, - {name: "unsupported type", input: 42, wantErr: true}, + for _, value := range AccessSourceCategories() { + if !value.IsValid() { + t.Fatalf("IsValid() = false for %q", value) + } } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { + if AccessSourceCategory("BOGUS").IsValid() { + t.Fatal("IsValid() = true for invalid value") + } +} + +func TestAccessSourceCategoryUnmarshalText(t *testing.T) { + t.Parallel() + + for _, value := range AccessSourceCategories() { + t.Run(string(value), func(t *testing.T) { t.Parallel() var got AccessSourceCategory - - err := got.Scan(tt.input) - if tt.wantErr { - if err == nil { - t.Fatalf("Scan(%v) expected error", tt.input) - } - - return + if err := got.UnmarshalText([]byte(value)); err != nil { + t.Fatalf("UnmarshalText(%q) returned error: %v", value, err) } + if got != value { + t.Fatalf("UnmarshalText(%q) = %q, want %q", value, got, value) + } + }) + } + + t.Run("invalid", func(t *testing.T) { + t.Parallel() + + var got AccessSourceCategory + if err := got.UnmarshalText([]byte("BOGUS")); err == nil { + t.Fatal("UnmarshalText(BOGUS) expected error") + } + }) +} + +func TestAccessSourceCategoryMarshalText(t *testing.T) { + t.Parallel() + + for _, value := range AccessSourceCategories() { + t.Run(string(value), func(t *testing.T) { + t.Parallel() + + got, err := value.MarshalText() if err != nil { - t.Fatalf("Scan(%v) returned error: %v", tt.input, err) + t.Fatalf("MarshalText() returned error: %v", err) } - if got != tt.want { - t.Fatalf("Scan(%v) = %q, want %q", tt.input, got, tt.want) + if string(got) != value.String() { + t.Fatalf("MarshalText() = %q, want %q", string(got), value.String()) } }) } } - -func TestAccessSourceCategoryValue(t *testing.T) { - t.Parallel() - - got, err := AccessSourceCategorySaaS.Value() - if err != nil { - t.Fatalf("Value() returned error: %v", err) - } - - if got != "SAAS" { - t.Fatalf("Value() = %q, want %q", got, "SAAS") - } -} diff --git a/pkg/coredata/access_source_order_field.go b/pkg/coredata/access_source_order_field.go index 3efa157e1..552dcb850 100644 --- a/pkg/coredata/access_source_order_field.go +++ b/pkg/coredata/access_source_order_field.go @@ -14,7 +14,12 @@ package coredata -import "fmt" +import ( + "encoding" + "fmt" + + "go.probo.inc/probo/pkg/page" +) type ( AccessSourceOrderField string @@ -24,6 +29,48 @@ const ( AccessSourceOrderFieldCreatedAt AccessSourceOrderField = "CREATED_AT" ) +var ( + _ page.OrderField = AccessSourceOrderField("") + _ fmt.Stringer = AccessSourceOrderField("") + _ encoding.TextMarshaler = AccessSourceOrderField("") + _ encoding.TextUnmarshaler = (*AccessSourceOrderField)(nil) +) + +func AccessSourceOrderFields() []AccessSourceOrderField { + return []AccessSourceOrderField{ + AccessSourceOrderFieldCreatedAt, + } +} + +func (v AccessSourceOrderField) IsValid() bool { + switch v { + case + AccessSourceOrderFieldCreatedAt: + return true + } + + return false +} + +func (v AccessSourceOrderField) String() string { + return string(v) +} + +func (v AccessSourceOrderField) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *AccessSourceOrderField) UnmarshalText(text []byte) error { + val := AccessSourceOrderField(text) + if !val.IsValid() { + return fmt.Errorf("invalid AccessSourceOrderField value: %q", string(text)) + } + + *v = val + + return nil +} + func (p AccessSourceOrderField) Column() string { switch p { case AccessSourceOrderFieldCreatedAt: @@ -32,29 +79,3 @@ func (p AccessSourceOrderField) Column() string { panic(fmt.Sprintf("unsupported order by: %s", p)) } - -func (p AccessSourceOrderField) IsValid() bool { - switch p { - case AccessSourceOrderFieldCreatedAt: - return true - } - - return false -} - -func (p AccessSourceOrderField) String() string { - return string(p) -} - -func (p AccessSourceOrderField) MarshalText() ([]byte, error) { - return []byte(p.String()), nil -} - -func (p *AccessSourceOrderField) UnmarshalText(text []byte) error { - *p = AccessSourceOrderField(text) - if !p.IsValid() { - return fmt.Errorf("%s is not a valid AccessSourceOrderField", string(text)) - } - - return nil -} diff --git a/pkg/coredata/agent_run.go b/pkg/coredata/agent_run.go index 4a7a18a2f..9f488aca5 100644 --- a/pkg/coredata/agent_run.go +++ b/pkg/coredata/agent_run.go @@ -16,6 +16,7 @@ package coredata import ( "context" + "encoding" "encoding/json" "errors" "fmt" @@ -60,6 +61,57 @@ const ( AgentRunStatusFailed AgentRunStatus = "FAILED" ) +var ( + _ fmt.Stringer = AgentRunStatus("") + _ encoding.TextMarshaler = AgentRunStatus("") + _ encoding.TextUnmarshaler = (*AgentRunStatus)(nil) +) + +func AgentRunStatuses() []AgentRunStatus { + return []AgentRunStatus{ + AgentRunStatusPending, + AgentRunStatusRunning, + AgentRunStatusSuspended, + AgentRunStatusAwaitingApproval, + AgentRunStatusCompleted, + AgentRunStatusFailed, + } +} + +func (v AgentRunStatus) IsValid() bool { + switch v { + case + AgentRunStatusPending, + AgentRunStatusRunning, + AgentRunStatusSuspended, + AgentRunStatusAwaitingApproval, + AgentRunStatusCompleted, + AgentRunStatusFailed: + return true + } + + return false +} + +func (v AgentRunStatus) String() string { + return string(v) +} + +func (v AgentRunStatus) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *AgentRunStatus) UnmarshalText(text []byte) error { + val := AgentRunStatus(text) + if !val.IsValid() { + return fmt.Errorf("invalid AgentRunStatus value: %q", string(text)) + } + + *v = val + + return nil +} + func (e AgentRun) CursorKey(orderBy AgentRunOrderField) page.CursorKey { switch orderBy { case AgentRunOrderFieldCreatedAt: diff --git a/pkg/coredata/agent_run_order_field.go b/pkg/coredata/agent_run_order_field.go index 56fe36556..50a002b7f 100644 --- a/pkg/coredata/agent_run_order_field.go +++ b/pkg/coredata/agent_run_order_field.go @@ -14,7 +14,12 @@ package coredata -import "fmt" +import ( + "encoding" + "fmt" + + "go.probo.inc/probo/pkg/page" +) type ( AgentRunOrderField string @@ -24,6 +29,48 @@ const ( AgentRunOrderFieldCreatedAt AgentRunOrderField = "CREATED_AT" ) +var ( + _ page.OrderField = AgentRunOrderField("") + _ fmt.Stringer = AgentRunOrderField("") + _ encoding.TextMarshaler = AgentRunOrderField("") + _ encoding.TextUnmarshaler = (*AgentRunOrderField)(nil) +) + +func AgentRunOrderFields() []AgentRunOrderField { + return []AgentRunOrderField{ + AgentRunOrderFieldCreatedAt, + } +} + +func (v AgentRunOrderField) IsValid() bool { + switch v { + case + AgentRunOrderFieldCreatedAt: + return true + } + + return false +} + +func (v AgentRunOrderField) String() string { + return string(v) +} + +func (v AgentRunOrderField) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *AgentRunOrderField) UnmarshalText(text []byte) error { + val := AgentRunOrderField(text) + if !val.IsValid() { + return fmt.Errorf("invalid AgentRunOrderField value: %q", string(text)) + } + + *v = val + + return nil +} + func (p AgentRunOrderField) Column() string { switch p { case AgentRunOrderFieldCreatedAt: @@ -32,29 +79,3 @@ func (p AgentRunOrderField) Column() string { panic(fmt.Sprintf("unsupported order by: %s", p)) } - -func (p AgentRunOrderField) IsValid() bool { - switch p { - case AgentRunOrderFieldCreatedAt: - return true - } - - return false -} - -func (p AgentRunOrderField) String() string { - return string(p) -} - -func (p *AgentRunOrderField) UnmarshalText(text []byte) error { - *p = AgentRunOrderField(text) - if !p.IsValid() { - return fmt.Errorf("%s is not a valid AgentRunOrderField", string(text)) - } - - return nil -} - -func (p AgentRunOrderField) MarshalText() ([]byte, error) { - return []byte(p.String()), nil -} diff --git a/pkg/coredata/applicability_statement_order_field.go b/pkg/coredata/applicability_statement_order_field.go index 3fc7eca53..4c826e469 100644 --- a/pkg/coredata/applicability_statement_order_field.go +++ b/pkg/coredata/applicability_statement_order_field.go @@ -15,7 +15,10 @@ package coredata import ( + "encoding" "fmt" + + "go.probo.inc/probo/pkg/page" ) type ApplicabilityStatementOrderField string @@ -25,6 +28,50 @@ const ( ApplicabilityStatementOrderFieldControlSectionTitle ApplicabilityStatementOrderField = "CONTROL_SECTION_TITLE" ) +var ( + _ page.OrderField = ApplicabilityStatementOrderField("") + _ fmt.Stringer = ApplicabilityStatementOrderField("") + _ encoding.TextMarshaler = ApplicabilityStatementOrderField("") + _ encoding.TextUnmarshaler = (*ApplicabilityStatementOrderField)(nil) +) + +func ApplicabilityStatementOrderFields() []ApplicabilityStatementOrderField { + return []ApplicabilityStatementOrderField{ + ApplicabilityStatementOrderFieldCreatedAt, + ApplicabilityStatementOrderFieldControlSectionTitle, + } +} + +func (v ApplicabilityStatementOrderField) IsValid() bool { + switch v { + case + ApplicabilityStatementOrderFieldCreatedAt, + ApplicabilityStatementOrderFieldControlSectionTitle: + return true + } + + return false +} + +func (v ApplicabilityStatementOrderField) String() string { + return string(v) +} + +func (v ApplicabilityStatementOrderField) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *ApplicabilityStatementOrderField) UnmarshalText(text []byte) error { + val := ApplicabilityStatementOrderField(text) + if !val.IsValid() { + return fmt.Errorf("invalid ApplicabilityStatementOrderField value: %q", string(text)) + } + + *v = val + + return nil +} + func (p ApplicabilityStatementOrderField) Column() string { switch p { case ApplicabilityStatementOrderFieldCreatedAt: @@ -35,23 +82,3 @@ func (p ApplicabilityStatementOrderField) Column() string { panic("unknown ApplicabilityStatementOrderField") } - -func (p ApplicabilityStatementOrderField) String() string { - return string(p) -} - -func (p ApplicabilityStatementOrderField) MarshalText() ([]byte, error) { - return []byte(p.String()), nil -} - -func (p *ApplicabilityStatementOrderField) UnmarshalText(text []byte) error { - val := string(text) - switch val { - case string(ApplicabilityStatementOrderFieldCreatedAt), - string(ApplicabilityStatementOrderFieldControlSectionTitle): - *p = ApplicabilityStatementOrderField(val) - return nil - } - - return fmt.Errorf("invalid ApplicabilityStatementOrderField value: %q", val) -} diff --git a/pkg/coredata/asset_order_field.go b/pkg/coredata/asset_order_field.go index 24079912e..408753821 100644 --- a/pkg/coredata/asset_order_field.go +++ b/pkg/coredata/asset_order_field.go @@ -14,6 +14,13 @@ package coredata +import ( + "encoding" + "fmt" + + "go.probo.inc/probo/pkg/page" +) + type AssetOrderField string const ( @@ -22,10 +29,52 @@ const ( AssetOrderFieldName AssetOrderField = "NAME" ) +var ( + _ page.OrderField = AssetOrderField("") + _ fmt.Stringer = AssetOrderField("") + _ encoding.TextMarshaler = AssetOrderField("") + _ encoding.TextUnmarshaler = (*AssetOrderField)(nil) +) + +func AssetOrderFields() []AssetOrderField { + return []AssetOrderField{ + AssetOrderFieldCreatedAt, + AssetOrderFieldAmount, + AssetOrderFieldName, + } +} + +func (v AssetOrderField) IsValid() bool { + switch v { + case + AssetOrderFieldCreatedAt, + AssetOrderFieldAmount, + AssetOrderFieldName: + return true + } + + return false +} + +func (v AssetOrderField) String() string { + return string(v) +} + +func (v AssetOrderField) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *AssetOrderField) UnmarshalText(text []byte) error { + val := AssetOrderField(text) + if !val.IsValid() { + return fmt.Errorf("invalid AssetOrderField value: %q", string(text)) + } + + *v = val + + return nil +} + func (p AssetOrderField) Column() string { return string(p) } - -func (p AssetOrderField) String() string { - return string(p) -} diff --git a/pkg/coredata/asset_type.go b/pkg/coredata/asset_type.go index eb46176c2..7aeb4e9c1 100644 --- a/pkg/coredata/asset_type.go +++ b/pkg/coredata/asset_type.go @@ -15,7 +15,7 @@ package coredata import ( - "database/sql/driver" + "encoding" "fmt" ) @@ -28,6 +28,12 @@ const ( AssetTypeVirtual AssetType = "VIRTUAL" ) +var ( + _ fmt.Stringer = AssetType("") + _ encoding.TextMarshaler = AssetType("") + _ encoding.TextUnmarshaler = (*AssetType)(nil) +) + func AssetTypes() []AssetType { return []AssetType{ AssetTypePhysical, @@ -35,38 +41,32 @@ func AssetTypes() []AssetType { } } -func (at AssetType) MarshalText() ([]byte, error) { - return []byte(at.String()), nil +func (v AssetType) IsValid() bool { + switch v { + case + AssetTypePhysical, + AssetTypeVirtual: + return true + } + + return false } -func (at *AssetType) UnmarshalText(data []byte) error { - val := string(data) +func (v AssetType) String() string { + return string(v) +} - switch val { - case AssetTypePhysical.String(): - *at = AssetTypePhysical - case AssetTypeVirtual.String(): - *at = AssetTypeVirtual - default: - return fmt.Errorf("invalid AssetType value: %q", val) +func (v AssetType) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *AssetType) UnmarshalText(text []byte) error { + val := AssetType(text) + if !val.IsValid() { + return fmt.Errorf("invalid AssetType value: %q", string(text)) } + *v = val + return nil } - -func (at AssetType) String() string { - return string(at) -} - -func (at *AssetType) Scan(value any) error { - val, ok := value.(string) - if !ok { - return fmt.Errorf("invalid scan source for AssetType, expected string got %T", value) - } - - return at.UnmarshalText([]byte(val)) -} - -func (at AssetType) Value() (driver.Value, error) { - return at.String(), nil -} diff --git a/pkg/coredata/audit_log_actor_type.go b/pkg/coredata/audit_log_actor_type.go index 97cb2cf48..19021c2e9 100644 --- a/pkg/coredata/audit_log_actor_type.go +++ b/pkg/coredata/audit_log_actor_type.go @@ -15,7 +15,7 @@ package coredata import ( - "database/sql/driver" + "encoding" "fmt" ) @@ -27,47 +27,47 @@ const ( AuditLogActorTypeSystem AuditLogActorType = "SYSTEM" ) -func (a AuditLogActorType) String() string { - return string(a) +var ( + _ fmt.Stringer = AuditLogActorType("") + _ encoding.TextMarshaler = AuditLogActorType("") + _ encoding.TextUnmarshaler = (*AuditLogActorType)(nil) +) + +func AuditLogActorTypes() []AuditLogActorType { + return []AuditLogActorType{ + AuditLogActorTypeUser, + AuditLogActorTypeAPIKey, + AuditLogActorTypeSystem, + } } -func (a AuditLogActorType) IsValid() bool { - switch a { - case AuditLogActorTypeUser, AuditLogActorTypeAPIKey, AuditLogActorTypeSystem: +func (v AuditLogActorType) IsValid() bool { + switch v { + case + AuditLogActorTypeUser, + AuditLogActorTypeAPIKey, + AuditLogActorTypeSystem: return true } return false } -func (a AuditLogActorType) MarshalText() ([]byte, error) { - return []byte(a.String()), nil +func (v AuditLogActorType) String() string { + return string(v) } -func (a *AuditLogActorType) UnmarshalText(text []byte) error { - *a = AuditLogActorType(text) - if !a.IsValid() { - return fmt.Errorf("%s is not a valid AuditLogActorType", string(text)) +func (v AuditLogActorType) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *AuditLogActorType) UnmarshalText(text []byte) error { + val := AuditLogActorType(text) + if !val.IsValid() { + return fmt.Errorf("invalid AuditLogActorType value: %q", string(text)) } + *v = val + return nil } - -func (a *AuditLogActorType) Scan(value any) error { - var s string - - switch v := value.(type) { - case string: - s = v - case []byte: - s = string(v) - default: - return fmt.Errorf("unsupported type for AuditLogActorType: %T", value) - } - - return a.UnmarshalText([]byte(s)) -} - -func (a AuditLogActorType) Value() (driver.Value, error) { - return a.String(), nil -} diff --git a/pkg/coredata/audit_log_entry_order_field.go b/pkg/coredata/audit_log_entry_order_field.go index 9cf304572..16413b385 100644 --- a/pkg/coredata/audit_log_entry_order_field.go +++ b/pkg/coredata/audit_log_entry_order_field.go @@ -15,7 +15,10 @@ package coredata import ( + "encoding" "fmt" + + "go.probo.inc/probo/pkg/page" ) type AuditLogEntryOrderField string @@ -24,6 +27,48 @@ const ( AuditLogEntryOrderFieldCreatedAt AuditLogEntryOrderField = "CREATED_AT" ) +var ( + _ page.OrderField = AuditLogEntryOrderField("") + _ fmt.Stringer = AuditLogEntryOrderField("") + _ encoding.TextMarshaler = AuditLogEntryOrderField("") + _ encoding.TextUnmarshaler = (*AuditLogEntryOrderField)(nil) +) + +func AuditLogEntryOrderFields() []AuditLogEntryOrderField { + return []AuditLogEntryOrderField{ + AuditLogEntryOrderFieldCreatedAt, + } +} + +func (v AuditLogEntryOrderField) IsValid() bool { + switch v { + case + AuditLogEntryOrderFieldCreatedAt: + return true + } + + return false +} + +func (v AuditLogEntryOrderField) String() string { + return string(v) +} + +func (v AuditLogEntryOrderField) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *AuditLogEntryOrderField) UnmarshalText(text []byte) error { + val := AuditLogEntryOrderField(text) + if !val.IsValid() { + return fmt.Errorf("invalid AuditLogEntryOrderField value: %q", string(text)) + } + + *v = val + + return nil +} + func (p AuditLogEntryOrderField) Column() string { switch p { case AuditLogEntryOrderFieldCreatedAt: @@ -32,29 +77,3 @@ func (p AuditLogEntryOrderField) Column() string { panic(fmt.Sprintf("unsupported order by: %s", p)) } - -func (p AuditLogEntryOrderField) String() string { - return string(p) -} - -func (p AuditLogEntryOrderField) IsValid() bool { - switch p { - case AuditLogEntryOrderFieldCreatedAt: - return true - } - - return false -} - -func (p AuditLogEntryOrderField) MarshalText() ([]byte, error) { - return []byte(p.String()), nil -} - -func (p *AuditLogEntryOrderField) UnmarshalText(text []byte) error { - *p = AuditLogEntryOrderField(text) - if !p.IsValid() { - return fmt.Errorf("%s is not a valid AuditLogEntryOrderField", string(text)) - } - - return nil -} diff --git a/pkg/coredata/audit_order_field.go b/pkg/coredata/audit_order_field.go index d1525f148..cbddf5d5e 100644 --- a/pkg/coredata/audit_order_field.go +++ b/pkg/coredata/audit_order_field.go @@ -15,7 +15,10 @@ package coredata import ( + "encoding" "fmt" + + "go.probo.inc/probo/pkg/page" ) type AuditOrderField string @@ -27,28 +30,54 @@ const ( AuditOrderFieldState AuditOrderField = "STATE" ) +var ( + _ page.OrderField = AuditOrderField("") + _ fmt.Stringer = AuditOrderField("") + _ encoding.TextMarshaler = AuditOrderField("") + _ encoding.TextUnmarshaler = (*AuditOrderField)(nil) +) + +func AuditOrderFields() []AuditOrderField { + return []AuditOrderField{ + AuditOrderFieldCreatedAt, + AuditOrderFieldValidFrom, + AuditOrderFieldValidUntil, + AuditOrderFieldState, + } +} + +func (v AuditOrderField) IsValid() bool { + switch v { + case + AuditOrderFieldCreatedAt, + AuditOrderFieldValidFrom, + AuditOrderFieldValidUntil, + AuditOrderFieldState: + return true + } + + return false +} + +func (v AuditOrderField) String() string { + return string(v) +} + +func (v AuditOrderField) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *AuditOrderField) UnmarshalText(text []byte) error { + val := AuditOrderField(text) + if !val.IsValid() { + return fmt.Errorf("invalid AuditOrderField value: %q", string(text)) + } + + *v = val + + return nil +} + func (p AuditOrderField) Column() string { return string(p) } - -func (p AuditOrderField) String() string { - return string(p) -} - -func (p AuditOrderField) MarshalText() ([]byte, error) { - return []byte(p.String()), nil -} - -func (p *AuditOrderField) UnmarshalText(text []byte) error { - val := string(text) - switch val { - case string(AuditOrderFieldCreatedAt), - string(AuditOrderFieldValidFrom), - string(AuditOrderFieldValidUntil), - string(AuditOrderFieldState): - *p = AuditOrderField(val) - return nil - } - - return fmt.Errorf("invalid AuditOrderField value: %q", val) -} diff --git a/pkg/coredata/audit_state.go b/pkg/coredata/audit_state.go index 227076c90..6ff3fd2bd 100644 --- a/pkg/coredata/audit_state.go +++ b/pkg/coredata/audit_state.go @@ -15,7 +15,7 @@ package coredata import ( - "database/sql/driver" + "encoding" "fmt" ) @@ -29,6 +29,12 @@ const ( AuditStateOutdated AuditState = "OUTDATED" ) +var ( + _ fmt.Stringer = AuditState("") + _ encoding.TextMarshaler = AuditState("") + _ encoding.TextUnmarshaler = (*AuditState)(nil) +) + func AuditStates() []AuditState { return []AuditState{ AuditStateNotStarted, @@ -39,40 +45,35 @@ func AuditStates() []AuditState { } } -func (as AuditState) String() string { - return string(as) +func (v AuditState) IsValid() bool { + switch v { + case + AuditStateNotStarted, + AuditStateInProgress, + AuditStateCompleted, + AuditStateRejected, + AuditStateOutdated: + return true + } + + return false } -func (as *AuditState) Scan(value any) error { - var s string +func (v AuditState) String() string { + return string(v) +} - switch v := value.(type) { - case string: - s = v - case []byte: - s = string(v) - default: - return fmt.Errorf("unsupported type for AuditState: %T", value) +func (v AuditState) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *AuditState) UnmarshalText(text []byte) error { + val := AuditState(text) + if !val.IsValid() { + return fmt.Errorf("invalid AuditState value: %q", string(text)) } - switch s { - case "NOT_STARTED": - *as = AuditStateNotStarted - case "IN_PROGRESS": - *as = AuditStateInProgress - case "COMPLETED": - *as = AuditStateCompleted - case "REJECTED": - *as = AuditStateRejected - case "OUTDATED": - *as = AuditStateOutdated - default: - return fmt.Errorf("invalid AuditState value: %q", s) - } + *v = val return nil } - -func (as AuditState) Value() (driver.Value, error) { - return as.String(), nil -} diff --git a/pkg/coredata/auth_method.go b/pkg/coredata/auth_method.go index 3255362ab..f629ba7cd 100644 --- a/pkg/coredata/auth_method.go +++ b/pkg/coredata/auth_method.go @@ -15,7 +15,7 @@ package coredata import ( - "database/sql/driver" + "encoding" "fmt" ) @@ -29,6 +29,12 @@ const ( AccessEntryAuthMethodUnknown AccessEntryAuthMethod = "UNKNOWN" ) +var ( + _ fmt.Stringer = AccessEntryAuthMethod("") + _ encoding.TextMarshaler = AccessEntryAuthMethod("") + _ encoding.TextUnmarshaler = (*AccessEntryAuthMethod)(nil) +) + func AccessEntryAuthMethods() []AccessEntryAuthMethod { return []AccessEntryAuthMethod{ AccessEntryAuthMethodSSO, @@ -39,40 +45,35 @@ func AccessEntryAuthMethods() []AccessEntryAuthMethod { } } -func (a AccessEntryAuthMethod) String() string { - return string(a) +func (v AccessEntryAuthMethod) IsValid() bool { + switch v { + case + AccessEntryAuthMethodSSO, + AccessEntryAuthMethodPassword, + AccessEntryAuthMethodAPIKey, + AccessEntryAuthMethodServiceAccount, + AccessEntryAuthMethodUnknown: + return true + } + + return false } -func (a *AccessEntryAuthMethod) Scan(value any) error { - var str string +func (v AccessEntryAuthMethod) String() string { + return string(v) +} - switch v := value.(type) { - case string: - str = v - case []byte: - str = string(v) - default: - return fmt.Errorf("cannot scan AccessEntryAuthMethod: unsupported type %T", value) +func (v AccessEntryAuthMethod) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *AccessEntryAuthMethod) UnmarshalText(text []byte) error { + val := AccessEntryAuthMethod(text) + if !val.IsValid() { + return fmt.Errorf("invalid AccessEntryAuthMethod value: %q", string(text)) } - switch str { - case "SSO": - *a = AccessEntryAuthMethodSSO - case "PASSWORD": - *a = AccessEntryAuthMethodPassword - case "API_KEY": - *a = AccessEntryAuthMethodAPIKey - case "SERVICE_ACCOUNT": - *a = AccessEntryAuthMethodServiceAccount - case "UNKNOWN": - *a = AccessEntryAuthMethodUnknown - default: - return fmt.Errorf("cannot parse AccessEntryAuthMethod: invalid value %q", str) - } + *v = val return nil } - -func (a AccessEntryAuthMethod) Value() (driver.Value, error) { - return a.String(), nil -} diff --git a/pkg/coredata/business_impact.go b/pkg/coredata/business_impact.go index cabbd7b63..858a27b04 100644 --- a/pkg/coredata/business_impact.go +++ b/pkg/coredata/business_impact.go @@ -15,8 +15,7 @@ package coredata import ( - "database/sql/driver" - "encoding/json" + "encoding" "fmt" ) @@ -29,6 +28,12 @@ const ( BusinessImpactCritical BusinessImpact = "CRITICAL" ) +var ( + _ fmt.Stringer = BusinessImpact("") + _ encoding.TextMarshaler = BusinessImpact("") + _ encoding.TextUnmarshaler = (*BusinessImpact)(nil) +) + func BusinessImpacts() []BusinessImpact { return []BusinessImpact{ BusinessImpactLow, @@ -38,76 +43,34 @@ func BusinessImpacts() []BusinessImpact { } } -func (i BusinessImpact) String() string { - return string(i) +func (v BusinessImpact) IsValid() bool { + switch v { + case + BusinessImpactLow, + BusinessImpactMedium, + BusinessImpactHigh, + BusinessImpactCritical: + return true + } + + return false } -func (i *BusinessImpact) Scan(value any) error { - switch v := value.(type) { - case string: - switch v { - case "LOW": - *i = BusinessImpactLow - case "MEDIUM": - *i = BusinessImpactMedium - case "HIGH": - *i = BusinessImpactHigh - case "CRITICAL": - *i = BusinessImpactCritical - default: - return fmt.Errorf("invalid BusinessImpact value: %q", v) - } - default: - return fmt.Errorf("unsupported type for BusinessImpact: %T", value) - } - - return nil -} - -func (i BusinessImpact) Value() (driver.Value, error) { - return i.String(), nil -} - -func (i BusinessImpact) MarshalJSON() ([]byte, error) { - return json.Marshal(i.String()) -} - -func (i *BusinessImpact) UnmarshalJSON(data []byte) error { - var s string - if err := json.Unmarshal(data, &s); err != nil { - return err - } - - switch s { - case "LOW": - *i = BusinessImpactLow - case "MEDIUM": - *i = BusinessImpactMedium - case "HIGH": - *i = BusinessImpactHigh - case "CRITICAL": - *i = BusinessImpactCritical - default: - return fmt.Errorf("invalid BusinessImpact value: %q", s) - } - - return nil -} - -func (i *BusinessImpact) UnmarshalText(text []byte) error { - s := string(text) - switch s { - case "LOW": - *i = BusinessImpactLow - case "MEDIUM": - *i = BusinessImpactMedium - case "HIGH": - *i = BusinessImpactHigh - case "CRITICAL": - *i = BusinessImpactCritical - default: - return fmt.Errorf("invalid BusinessImpact value: %q", s) +func (v BusinessImpact) String() string { + return string(v) +} + +func (v BusinessImpact) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *BusinessImpact) UnmarshalText(text []byte) error { + val := BusinessImpact(text) + if !val.IsValid() { + return fmt.Errorf("invalid BusinessImpact value: %q", string(text)) } + *v = val + return nil } diff --git a/pkg/coredata/compliance_external_url_order_field.go b/pkg/coredata/compliance_external_url_order_field.go index 7fd53b2e2..b9d368360 100644 --- a/pkg/coredata/compliance_external_url_order_field.go +++ b/pkg/coredata/compliance_external_url_order_field.go @@ -14,6 +14,13 @@ package coredata +import ( + "encoding" + "fmt" + + "go.probo.inc/probo/pkg/page" +) + type ( ComplianceExternalURLOrderField string ) @@ -23,6 +30,50 @@ const ( ComplianceExternalURLOrderFieldRank ComplianceExternalURLOrderField = "RANK" ) +var ( + _ page.OrderField = ComplianceExternalURLOrderField("") + _ fmt.Stringer = ComplianceExternalURLOrderField("") + _ encoding.TextMarshaler = ComplianceExternalURLOrderField("") + _ encoding.TextUnmarshaler = (*ComplianceExternalURLOrderField)(nil) +) + +func ComplianceExternalURLOrderFields() []ComplianceExternalURLOrderField { + return []ComplianceExternalURLOrderField{ + ComplianceExternalURLOrderFieldCreatedAt, + ComplianceExternalURLOrderFieldRank, + } +} + +func (v ComplianceExternalURLOrderField) IsValid() bool { + switch v { + case + ComplianceExternalURLOrderFieldCreatedAt, + ComplianceExternalURLOrderFieldRank: + return true + } + + return false +} + +func (v ComplianceExternalURLOrderField) String() string { + return string(v) +} + +func (v ComplianceExternalURLOrderField) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *ComplianceExternalURLOrderField) UnmarshalText(text []byte) error { + val := ComplianceExternalURLOrderField(text) + if !val.IsValid() { + return fmt.Errorf("invalid ComplianceExternalURLOrderField value: %q", string(text)) + } + + *v = val + + return nil +} + func (p ComplianceExternalURLOrderField) Column() string { switch p { case ComplianceExternalURLOrderFieldCreatedAt: @@ -33,16 +84,3 @@ func (p ComplianceExternalURLOrderField) Column() string { return string(p) } } - -func (p ComplianceExternalURLOrderField) String() string { - return string(p) -} - -func (p ComplianceExternalURLOrderField) MarshalText() ([]byte, error) { - return []byte(p.String()), nil -} - -func (p *ComplianceExternalURLOrderField) UnmarshalText(text []byte) error { - *p = ComplianceExternalURLOrderField(text) - return nil -} diff --git a/pkg/coredata/compliance_framework_order_field.go b/pkg/coredata/compliance_framework_order_field.go index f4a66f497..88063e619 100644 --- a/pkg/coredata/compliance_framework_order_field.go +++ b/pkg/coredata/compliance_framework_order_field.go @@ -14,6 +14,13 @@ package coredata +import ( + "encoding" + "fmt" + + "go.probo.inc/probo/pkg/page" +) + type ( ComplianceFrameworkOrderField string ) @@ -23,6 +30,50 @@ const ( ComplianceFrameworkOrderFieldRank ComplianceFrameworkOrderField = "RANK" ) +var ( + _ page.OrderField = ComplianceFrameworkOrderField("") + _ fmt.Stringer = ComplianceFrameworkOrderField("") + _ encoding.TextMarshaler = ComplianceFrameworkOrderField("") + _ encoding.TextUnmarshaler = (*ComplianceFrameworkOrderField)(nil) +) + +func ComplianceFrameworkOrderFields() []ComplianceFrameworkOrderField { + return []ComplianceFrameworkOrderField{ + ComplianceFrameworkOrderFieldCreatedAt, + ComplianceFrameworkOrderFieldRank, + } +} + +func (v ComplianceFrameworkOrderField) IsValid() bool { + switch v { + case + ComplianceFrameworkOrderFieldCreatedAt, + ComplianceFrameworkOrderFieldRank: + return true + } + + return false +} + +func (v ComplianceFrameworkOrderField) String() string { + return string(v) +} + +func (v ComplianceFrameworkOrderField) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *ComplianceFrameworkOrderField) UnmarshalText(text []byte) error { + val := ComplianceFrameworkOrderField(text) + if !val.IsValid() { + return fmt.Errorf("invalid ComplianceFrameworkOrderField value: %q", string(text)) + } + + *v = val + + return nil +} + func (p ComplianceFrameworkOrderField) Column() string { switch p { case ComplianceFrameworkOrderFieldCreatedAt: @@ -33,16 +84,3 @@ func (p ComplianceFrameworkOrderField) Column() string { return string(p) } } - -func (p ComplianceFrameworkOrderField) String() string { - return string(p) -} - -func (p ComplianceFrameworkOrderField) MarshalText() ([]byte, error) { - return []byte(p.String()), nil -} - -func (p *ComplianceFrameworkOrderField) UnmarshalText(text []byte) error { - *p = ComplianceFrameworkOrderField(text) - return nil -} diff --git a/pkg/coredata/compliance_framework_visibility.go b/pkg/coredata/compliance_framework_visibility.go index 775911990..7697398a6 100644 --- a/pkg/coredata/compliance_framework_visibility.go +++ b/pkg/coredata/compliance_framework_visibility.go @@ -14,6 +14,11 @@ package coredata +import ( + "encoding" + "fmt" +) + type ComplianceFrameworkVisibility string const ( @@ -21,6 +26,45 @@ const ( ComplianceFrameworkVisibilityPublic ComplianceFrameworkVisibility = "PUBLIC" ) +var ( + _ fmt.Stringer = ComplianceFrameworkVisibility("") + _ encoding.TextMarshaler = ComplianceFrameworkVisibility("") + _ encoding.TextUnmarshaler = (*ComplianceFrameworkVisibility)(nil) +) + +func ComplianceFrameworkVisibilities() []ComplianceFrameworkVisibility { + return []ComplianceFrameworkVisibility{ + ComplianceFrameworkVisibilityNone, + ComplianceFrameworkVisibilityPublic, + } +} + +func (v ComplianceFrameworkVisibility) IsValid() bool { + switch v { + case + ComplianceFrameworkVisibilityNone, + ComplianceFrameworkVisibilityPublic: + return true + } + + return false +} + func (v ComplianceFrameworkVisibility) String() string { return string(v) } + +func (v ComplianceFrameworkVisibility) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *ComplianceFrameworkVisibility) UnmarshalText(text []byte) error { + val := ComplianceFrameworkVisibility(text) + if !val.IsValid() { + return fmt.Errorf("invalid ComplianceFrameworkVisibility value: %q", string(text)) + } + + *v = val + + return nil +} diff --git a/pkg/coredata/connector_order_field.go b/pkg/coredata/connector_order_field.go index ed9a9b9db..8602258f0 100644 --- a/pkg/coredata/connector_order_field.go +++ b/pkg/coredata/connector_order_field.go @@ -14,6 +14,13 @@ package coredata +import ( + "encoding" + "fmt" + + "go.probo.inc/probo/pkg/page" +) + type ( ConnectorOrderField string ) @@ -23,19 +30,50 @@ const ( ConnectorOrderFieldProvider ConnectorOrderField = "PROVIDER" ) +var ( + _ page.OrderField = ConnectorOrderField("") + _ fmt.Stringer = ConnectorOrderField("") + _ encoding.TextMarshaler = ConnectorOrderField("") + _ encoding.TextUnmarshaler = (*ConnectorOrderField)(nil) +) + +func ConnectorOrderFields() []ConnectorOrderField { + return []ConnectorOrderField{ + ConnectorOrderFieldCreatedAt, + ConnectorOrderFieldProvider, + } +} + +func (v ConnectorOrderField) IsValid() bool { + switch v { + case + ConnectorOrderFieldCreatedAt, + ConnectorOrderFieldProvider: + return true + } + + return false +} + +func (v ConnectorOrderField) String() string { + return string(v) +} + +func (v ConnectorOrderField) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *ConnectorOrderField) UnmarshalText(text []byte) error { + val := ConnectorOrderField(text) + if !val.IsValid() { + return fmt.Errorf("invalid ConnectorOrderField value: %q", string(text)) + } + + *v = val + + return nil +} + func (p ConnectorOrderField) Column() string { return string(p) } - -func (p ConnectorOrderField) String() string { - return string(p) -} - -func (p ConnectorOrderField) MarshalText() ([]byte, error) { - return []byte(p.String()), nil -} - -func (p *ConnectorOrderField) UnmarshalText(text []byte) error { - *p = ConnectorOrderField(text) - return nil -} diff --git a/pkg/coredata/connector_protocol.go b/pkg/coredata/connector_protocol.go index 757eb0404..af8680d2d 100644 --- a/pkg/coredata/connector_protocol.go +++ b/pkg/coredata/connector_protocol.go @@ -15,7 +15,7 @@ package coredata import ( - "database/sql/driver" + "encoding" "fmt" ) @@ -26,6 +26,12 @@ const ( ConnectorProtocolAPIKey ConnectorProtocol = "API_KEY" ) +var ( + _ fmt.Stringer = ConnectorProtocol("") + _ encoding.TextMarshaler = ConnectorProtocol("") + _ encoding.TextUnmarshaler = (*ConnectorProtocol)(nil) +) + func ConnectorProtocols() []ConnectorProtocol { return []ConnectorProtocol{ ConnectorProtocolOAuth2, @@ -33,34 +39,32 @@ func ConnectorProtocols() []ConnectorProtocol { } } -func (cp ConnectorProtocol) String() string { - return string(cp) +func (v ConnectorProtocol) IsValid() bool { + switch v { + case + ConnectorProtocolOAuth2, + ConnectorProtocolAPIKey: + return true + } + + return false } -func (cp *ConnectorProtocol) Scan(value any) error { - var s string +func (v ConnectorProtocol) String() string { + return string(v) +} - switch v := value.(type) { - case string: - s = v - case []byte: - s = string(v) - default: - return fmt.Errorf("unsupported type for ConnectorProtocol: %T", value) +func (v ConnectorProtocol) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *ConnectorProtocol) UnmarshalText(text []byte) error { + val := ConnectorProtocol(text) + if !val.IsValid() { + return fmt.Errorf("invalid ConnectorProtocol value: %q", string(text)) } - switch s { - case "OAUTH2": - *cp = ConnectorProtocolOAuth2 - case "API_KEY": - *cp = ConnectorProtocolAPIKey - default: - return fmt.Errorf("invalid ConnectorProtocol value: %q", s) - } + *v = val return nil } - -func (cp ConnectorProtocol) Value() (driver.Value, error) { - return cp.String(), nil -} diff --git a/pkg/coredata/connector_provider.go b/pkg/coredata/connector_provider.go index 9737de78a..bd786753f 100644 --- a/pkg/coredata/connector_provider.go +++ b/pkg/coredata/connector_provider.go @@ -15,7 +15,7 @@ package coredata import ( - "database/sql/driver" + "encoding" "fmt" ) @@ -51,6 +51,12 @@ const ( ConnectorProviderMonday ConnectorProvider = "MONDAY" ) +var ( + _ fmt.Stringer = ConnectorProvider("") + _ encoding.TextMarshaler = ConnectorProvider("") + _ encoding.TextUnmarshaler = (*ConnectorProvider)(nil) +) + func ConnectorProviders() []ConnectorProvider { return []ConnectorProvider{ ConnectorProviderSlack, @@ -82,82 +88,56 @@ func ConnectorProviders() []ConnectorProvider { } } -func (cp ConnectorProvider) String() string { - return string(cp) +func (v ConnectorProvider) IsValid() bool { + switch v { + case + ConnectorProviderSlack, + ConnectorProviderGoogleWorkspace, + ConnectorProviderLinear, + ConnectorProviderOnePassword, + ConnectorProviderHubSpot, + ConnectorProviderDocuSign, + ConnectorProviderNotion, + ConnectorProviderBrex, + ConnectorProviderTally, + ConnectorProviderCloudflare, + ConnectorProviderOpenAI, + ConnectorProviderSentry, + ConnectorProviderSupabase, + ConnectorProviderGitHub, + ConnectorProviderIntercom, + ConnectorProviderResend, + ConnectorProviderMicrosoft365, + ConnectorProviderGitLab, + ConnectorProviderBitbucket, + ConnectorProviderHeroku, + ConnectorProviderPagerDuty, + ConnectorProviderAsana, + ConnectorProviderNetlify, + ConnectorProviderClickUp, + ConnectorProviderVercel, + ConnectorProviderMonday: + return true + } + + return false } -func (cp *ConnectorProvider) Scan(value any) error { - var s string +func (v ConnectorProvider) String() string { + return string(v) +} - switch v := value.(type) { - case string: - s = v - case []byte: - s = string(v) - default: - return fmt.Errorf("unsupported type for ConnectorProvider: %T", value) +func (v ConnectorProvider) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *ConnectorProvider) UnmarshalText(text []byte) error { + val := ConnectorProvider(text) + if !val.IsValid() { + return fmt.Errorf("invalid ConnectorProvider value: %q", string(text)) } - switch s { - case "SLACK": - *cp = ConnectorProviderSlack - case "GOOGLE_WORKSPACE": - *cp = ConnectorProviderGoogleWorkspace - case "LINEAR": - *cp = ConnectorProviderLinear - case "ONE_PASSWORD": - *cp = ConnectorProviderOnePassword - case "HUBSPOT": - *cp = ConnectorProviderHubSpot - case "DOCUSIGN": - *cp = ConnectorProviderDocuSign - case "NOTION": - *cp = ConnectorProviderNotion - case "BREX": - *cp = ConnectorProviderBrex - case "TALLY": - *cp = ConnectorProviderTally - case "CLOUDFLARE": - *cp = ConnectorProviderCloudflare - case "OPENAI": - *cp = ConnectorProviderOpenAI - case "SENTRY": - *cp = ConnectorProviderSentry - case "SUPABASE": - *cp = ConnectorProviderSupabase - case "GITHUB": - *cp = ConnectorProviderGitHub - case "INTERCOM": - *cp = ConnectorProviderIntercom - case "RESEND": - *cp = ConnectorProviderResend - case "MICROSOFT_365": - *cp = ConnectorProviderMicrosoft365 - case "GITLAB": - *cp = ConnectorProviderGitLab - case "BITBUCKET": - *cp = ConnectorProviderBitbucket - case "HEROKU": - *cp = ConnectorProviderHeroku - case "PAGERDUTY": - *cp = ConnectorProviderPagerDuty - case "ASANA": - *cp = ConnectorProviderAsana - case "NETLIFY": - *cp = ConnectorProviderNetlify - case "CLICKUP": - *cp = ConnectorProviderClickUp - case "VERCEL": - *cp = ConnectorProviderVercel - case "MONDAY": - *cp = ConnectorProviderMonday - default: - return fmt.Errorf("invalid ConnectorProvider value: %q", s) - } + *v = val return nil } - -func (cp ConnectorProvider) Value() (driver.Value, error) { - return cp.String(), nil -} diff --git a/pkg/coredata/control_maturity_level.go b/pkg/coredata/control_maturity_level.go index 7caf66a1d..fe63d3a06 100644 --- a/pkg/coredata/control_maturity_level.go +++ b/pkg/coredata/control_maturity_level.go @@ -15,7 +15,7 @@ package coredata import ( - "database/sql/driver" + "encoding" "fmt" ) @@ -32,6 +32,12 @@ const ( ControlMaturityLevelOptimizing ControlMaturityLevel = "OPTIMIZING" ) +var ( + _ fmt.Stringer = ControlMaturityLevel("") + _ encoding.TextMarshaler = ControlMaturityLevel("") + _ encoding.TextUnmarshaler = (*ControlMaturityLevel)(nil) +) + func ControlMaturityLevels() []ControlMaturityLevel { return []ControlMaturityLevel{ ControlMaturityLevelNone, @@ -43,9 +49,10 @@ func ControlMaturityLevels() []ControlMaturityLevel { } } -func (l ControlMaturityLevel) IsValid() bool { - switch l { - case ControlMaturityLevelNone, +func (v ControlMaturityLevel) IsValid() bool { + switch v { + case + ControlMaturityLevelNone, ControlMaturityLevelInitial, ControlMaturityLevelManaged, ControlMaturityLevelDefined, @@ -57,34 +64,21 @@ func (l ControlMaturityLevel) IsValid() bool { return false } -func (l ControlMaturityLevel) String() string { - return string(l) +func (v ControlMaturityLevel) String() string { + return string(v) } -func (l ControlMaturityLevel) MarshalText() ([]byte, error) { - return []byte(l.String()), nil +func (v ControlMaturityLevel) MarshalText() ([]byte, error) { + return []byte(v.String()), nil } -func (l *ControlMaturityLevel) UnmarshalText(data []byte) error { - val := ControlMaturityLevel(data) +func (v *ControlMaturityLevel) UnmarshalText(text []byte) error { + val := ControlMaturityLevel(text) if !val.IsValid() { - return fmt.Errorf("invalid ControlMaturityLevel value: %q", string(data)) + return fmt.Errorf("invalid ControlMaturityLevel value: %q", string(text)) } - *l = val + *v = val return nil } - -func (l *ControlMaturityLevel) Scan(value any) error { - val, ok := value.(string) - if !ok { - return fmt.Errorf("invalid scan source for ControlMaturityLevel, expected string got %T", value) - } - - return l.UnmarshalText([]byte(val)) -} - -func (l ControlMaturityLevel) Value() (driver.Value, error) { - return l.String(), nil -} diff --git a/pkg/coredata/control_maturity_level_test.go b/pkg/coredata/control_maturity_level_test.go index f3233ccb4..a6afc3e6b 100644 --- a/pkg/coredata/control_maturity_level_test.go +++ b/pkg/coredata/control_maturity_level_test.go @@ -45,83 +45,6 @@ func TestControlMaturityLevelIsValid(t *testing.T) { } } -func TestControlMaturityLevelScan(t *testing.T) { - t.Parallel() - - tests := []struct { - name string - input any - want ControlMaturityLevel - wantErr bool - }{ - {name: "none string", input: "NONE", want: ControlMaturityLevelNone}, - {name: "initial string", input: "INITIAL", want: ControlMaturityLevelInitial}, - {name: "managed string", input: "MANAGED", want: ControlMaturityLevelManaged}, - {name: "defined string", input: "DEFINED", want: ControlMaturityLevelDefined}, - {name: "quantitatively managed string", input: "QUANTITATIVELY_MANAGED", want: ControlMaturityLevelQuantitativelyManaged}, - {name: "optimizing string", input: "OPTIMIZING", want: ControlMaturityLevelOptimizing}, - {name: "invalid value", input: "BOGUS", wantErr: true}, - {name: "unsupported type", input: 42, wantErr: true}, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - t.Parallel() - - var got ControlMaturityLevel - - err := got.Scan(tt.input) - if tt.wantErr { - if err == nil { - t.Fatalf("Scan(%v) expected error", tt.input) - } - - return - } - - if err != nil { - t.Fatalf("Scan(%v) returned error: %v", tt.input, err) - } - - if got != tt.want { - t.Fatalf("Scan(%v) = %q, want %q", tt.input, got, tt.want) - } - }) - } -} - -func TestControlMaturityLevelValue(t *testing.T) { - t.Parallel() - - tests := []struct { - name string - level ControlMaturityLevel - want string - }{ - {name: "none", level: ControlMaturityLevelNone, want: "NONE"}, - {name: "initial", level: ControlMaturityLevelInitial, want: "INITIAL"}, - {name: "managed", level: ControlMaturityLevelManaged, want: "MANAGED"}, - {name: "defined", level: ControlMaturityLevelDefined, want: "DEFINED"}, - {name: "quantitatively managed", level: ControlMaturityLevelQuantitativelyManaged, want: "QUANTITATIVELY_MANAGED"}, - {name: "optimizing", level: ControlMaturityLevelOptimizing, want: "OPTIMIZING"}, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - t.Parallel() - - got, err := tt.level.Value() - if err != nil { - t.Fatalf("Value() returned error: %v", err) - } - - if got != tt.want { - t.Fatalf("Value() = %q, want %q", got, tt.want) - } - }) - } -} - func TestControlMaturityLevelMarshalUnmarshalText(t *testing.T) { t.Parallel() diff --git a/pkg/coredata/control_order_field.go b/pkg/coredata/control_order_field.go index a7a88ab66..8551f1175 100644 --- a/pkg/coredata/control_order_field.go +++ b/pkg/coredata/control_order_field.go @@ -14,6 +14,13 @@ package coredata +import ( + "encoding" + "fmt" + + "go.probo.inc/probo/pkg/page" +) + type ( ControlOrderField string ) @@ -23,6 +30,50 @@ const ( ControlOrderFieldSectionTitle ControlOrderField = "SECTION_TITLE" ) +var ( + _ page.OrderField = ControlOrderField("") + _ fmt.Stringer = ControlOrderField("") + _ encoding.TextMarshaler = ControlOrderField("") + _ encoding.TextUnmarshaler = (*ControlOrderField)(nil) +) + +func ControlOrderFields() []ControlOrderField { + return []ControlOrderField{ + ControlOrderFieldCreatedAt, + ControlOrderFieldSectionTitle, + } +} + +func (v ControlOrderField) IsValid() bool { + switch v { + case + ControlOrderFieldCreatedAt, + ControlOrderFieldSectionTitle: + return true + } + + return false +} + +func (v ControlOrderField) String() string { + return string(v) +} + +func (v ControlOrderField) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *ControlOrderField) UnmarshalText(text []byte) error { + val := ControlOrderField(text) + if !val.IsValid() { + return fmt.Errorf("invalid ControlOrderField value: %q", string(text)) + } + + *v = val + + return nil +} + func (p ControlOrderField) Column() string { switch p { case ControlOrderFieldCreatedAt: @@ -33,16 +84,3 @@ func (p ControlOrderField) Column() string { return string(p) } } - -func (p ControlOrderField) String() string { - return string(p) -} - -func (p ControlOrderField) MarshalText() ([]byte, error) { - return []byte(p.String()), nil -} - -func (p *ControlOrderField) UnmarshalText(text []byte) error { - *p = ControlOrderField(text) - return nil -} diff --git a/pkg/coredata/cookie_banner_order_field.go b/pkg/coredata/cookie_banner_order_field.go index 3ab8d6c38..691f9a4ef 100644 --- a/pkg/coredata/cookie_banner_order_field.go +++ b/pkg/coredata/cookie_banner_order_field.go @@ -14,7 +14,12 @@ package coredata -import "fmt" +import ( + "encoding" + "fmt" + + "go.probo.inc/probo/pkg/page" +) type CookieBannerOrderField string @@ -22,6 +27,48 @@ const ( CookieBannerOrderFieldCreatedAt CookieBannerOrderField = "CREATED_AT" ) +var ( + _ page.OrderField = CookieBannerOrderField("") + _ fmt.Stringer = CookieBannerOrderField("") + _ encoding.TextMarshaler = CookieBannerOrderField("") + _ encoding.TextUnmarshaler = (*CookieBannerOrderField)(nil) +) + +func CookieBannerOrderFields() []CookieBannerOrderField { + return []CookieBannerOrderField{ + CookieBannerOrderFieldCreatedAt, + } +} + +func (v CookieBannerOrderField) IsValid() bool { + switch v { + case + CookieBannerOrderFieldCreatedAt: + return true + } + + return false +} + +func (v CookieBannerOrderField) String() string { + return string(v) +} + +func (v CookieBannerOrderField) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *CookieBannerOrderField) UnmarshalText(text []byte) error { + val := CookieBannerOrderField(text) + if !val.IsValid() { + return fmt.Errorf("invalid CookieBannerOrderField value: %q", string(text)) + } + + *v = val + + return nil +} + func (p CookieBannerOrderField) Column() string { switch p { case CookieBannerOrderFieldCreatedAt: @@ -30,29 +77,3 @@ func (p CookieBannerOrderField) Column() string { panic(fmt.Sprintf("unsupported order by: %s", p)) } - -func (p CookieBannerOrderField) IsValid() bool { - switch p { - case CookieBannerOrderFieldCreatedAt: - return true - } - - return false -} - -func (p CookieBannerOrderField) String() string { - return string(p) -} - -func (p *CookieBannerOrderField) UnmarshalText(text []byte) error { - *p = CookieBannerOrderField(text) - if !p.IsValid() { - return fmt.Errorf("%s is not a valid CookieBannerOrderField", string(text)) - } - - return nil -} - -func (p CookieBannerOrderField) MarshalText() ([]byte, error) { - return []byte(p.String()), nil -} diff --git a/pkg/coredata/cookie_banner_state.go b/pkg/coredata/cookie_banner_state.go index c10fae942..79797f591 100644 --- a/pkg/coredata/cookie_banner_state.go +++ b/pkg/coredata/cookie_banner_state.go @@ -15,7 +15,7 @@ package coredata import ( - "database/sql/driver" + "encoding" "fmt" ) @@ -26,6 +26,12 @@ const ( CookieBannerStateInactive CookieBannerState = "INACTIVE" ) +var ( + _ fmt.Stringer = CookieBannerState("") + _ encoding.TextMarshaler = CookieBannerState("") + _ encoding.TextUnmarshaler = (*CookieBannerState)(nil) +) + func CookieBannerStates() []CookieBannerState { return []CookieBannerState{ CookieBannerStateActive, @@ -33,40 +39,32 @@ func CookieBannerStates() []CookieBannerState { } } -func (s CookieBannerState) String() string { - return string(s) +func (v CookieBannerState) IsValid() bool { + switch v { + case + CookieBannerStateActive, + CookieBannerStateInactive: + return true + } + + return false } -func (s *CookieBannerState) Scan(value any) error { - var v string +func (v CookieBannerState) String() string { + return string(v) +} - switch val := value.(type) { - case string: - v = val - case []byte: - v = string(val) - default: - return fmt.Errorf("unsupported type for CookieBannerState: %T", value) +func (v CookieBannerState) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *CookieBannerState) UnmarshalText(text []byte) error { + val := CookieBannerState(text) + if !val.IsValid() { + return fmt.Errorf("invalid CookieBannerState value: %q", string(text)) } - switch CookieBannerState(v) { - case CookieBannerStateActive: - *s = CookieBannerStateActive - case CookieBannerStateInactive: - *s = CookieBannerStateInactive - default: - return fmt.Errorf("invalid CookieBannerState value: %q", v) - } + *v = val return nil } - -func (s CookieBannerState) Value() (driver.Value, error) { - switch s { - case CookieBannerStateActive, - CookieBannerStateInactive: - return string(s), nil - default: - return nil, fmt.Errorf("invalid CookieBannerState: %s", s) - } -} diff --git a/pkg/coredata/cookie_banner_version_order_field.go b/pkg/coredata/cookie_banner_version_order_field.go index 258c1fbf1..6e7506f86 100644 --- a/pkg/coredata/cookie_banner_version_order_field.go +++ b/pkg/coredata/cookie_banner_version_order_field.go @@ -14,7 +14,12 @@ package coredata -import "fmt" +import ( + "encoding" + "fmt" + + "go.probo.inc/probo/pkg/page" +) type CookieBannerVersionOrderField string @@ -22,6 +27,48 @@ const ( CookieBannerVersionOrderFieldCreatedAt CookieBannerVersionOrderField = "CREATED_AT" ) +var ( + _ page.OrderField = CookieBannerVersionOrderField("") + _ fmt.Stringer = CookieBannerVersionOrderField("") + _ encoding.TextMarshaler = CookieBannerVersionOrderField("") + _ encoding.TextUnmarshaler = (*CookieBannerVersionOrderField)(nil) +) + +func CookieBannerVersionOrderFields() []CookieBannerVersionOrderField { + return []CookieBannerVersionOrderField{ + CookieBannerVersionOrderFieldCreatedAt, + } +} + +func (v CookieBannerVersionOrderField) IsValid() bool { + switch v { + case + CookieBannerVersionOrderFieldCreatedAt: + return true + } + + return false +} + +func (v CookieBannerVersionOrderField) String() string { + return string(v) +} + +func (v CookieBannerVersionOrderField) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *CookieBannerVersionOrderField) UnmarshalText(text []byte) error { + val := CookieBannerVersionOrderField(text) + if !val.IsValid() { + return fmt.Errorf("invalid CookieBannerVersionOrderField value: %q", string(text)) + } + + *v = val + + return nil +} + func (p CookieBannerVersionOrderField) Column() string { switch p { case CookieBannerVersionOrderFieldCreatedAt: @@ -30,29 +77,3 @@ func (p CookieBannerVersionOrderField) Column() string { panic(fmt.Sprintf("unsupported order by: %s", p)) } - -func (p CookieBannerVersionOrderField) IsValid() bool { - switch p { - case CookieBannerVersionOrderFieldCreatedAt: - return true - } - - return false -} - -func (p CookieBannerVersionOrderField) String() string { - return string(p) -} - -func (p *CookieBannerVersionOrderField) UnmarshalText(text []byte) error { - *p = CookieBannerVersionOrderField(text) - if !p.IsValid() { - return fmt.Errorf("%s is not a valid CookieBannerVersionOrderField", string(text)) - } - - return nil -} - -func (p CookieBannerVersionOrderField) MarshalText() ([]byte, error) { - return []byte(p.String()), nil -} diff --git a/pkg/coredata/cookie_banner_version_state.go b/pkg/coredata/cookie_banner_version_state.go index 5ce8625b3..5c0dafdf0 100644 --- a/pkg/coredata/cookie_banner_version_state.go +++ b/pkg/coredata/cookie_banner_version_state.go @@ -15,7 +15,7 @@ package coredata import ( - "database/sql/driver" + "encoding" "fmt" ) @@ -26,6 +26,12 @@ const ( CookieBannerVersionStatePublished CookieBannerVersionState = "PUBLISHED" ) +var ( + _ fmt.Stringer = CookieBannerVersionState("") + _ encoding.TextMarshaler = CookieBannerVersionState("") + _ encoding.TextUnmarshaler = (*CookieBannerVersionState)(nil) +) + func CookieBannerVersionStates() []CookieBannerVersionState { return []CookieBannerVersionState{ CookieBannerVersionStateDraft, @@ -33,40 +39,32 @@ func CookieBannerVersionStates() []CookieBannerVersionState { } } -func (s CookieBannerVersionState) String() string { - return string(s) +func (v CookieBannerVersionState) IsValid() bool { + switch v { + case + CookieBannerVersionStateDraft, + CookieBannerVersionStatePublished: + return true + } + + return false } -func (s *CookieBannerVersionState) Scan(value any) error { - var v string +func (v CookieBannerVersionState) String() string { + return string(v) +} - switch val := value.(type) { - case string: - v = val - case []byte: - v = string(val) - default: - return fmt.Errorf("unsupported type for CookieBannerVersionState: %T", value) +func (v CookieBannerVersionState) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *CookieBannerVersionState) UnmarshalText(text []byte) error { + val := CookieBannerVersionState(text) + if !val.IsValid() { + return fmt.Errorf("invalid CookieBannerVersionState value: %q", string(text)) } - switch CookieBannerVersionState(v) { - case CookieBannerVersionStateDraft: - *s = CookieBannerVersionStateDraft - case CookieBannerVersionStatePublished: - *s = CookieBannerVersionStatePublished - default: - return fmt.Errorf("invalid CookieBannerVersionState value: %q", v) - } + *v = val return nil } - -func (s CookieBannerVersionState) Value() (driver.Value, error) { - switch s { - case CookieBannerVersionStateDraft, - CookieBannerVersionStatePublished: - return string(s), nil - default: - return nil, fmt.Errorf("invalid CookieBannerVersionState: %s", s) - } -} diff --git a/pkg/coredata/cookie_category_kind.go b/pkg/coredata/cookie_category_kind.go index d68f7ae57..3d03e6ab1 100644 --- a/pkg/coredata/cookie_category_kind.go +++ b/pkg/coredata/cookie_category_kind.go @@ -14,6 +14,11 @@ package coredata +import ( + "encoding" + "fmt" +) + type CookieCategoryKind string const ( @@ -22,6 +27,51 @@ const ( CookieCategoryKindUncategorised CookieCategoryKind = "UNCATEGORISED" ) +var ( + _ fmt.Stringer = CookieCategoryKind("") + _ encoding.TextMarshaler = CookieCategoryKind("") + _ encoding.TextUnmarshaler = (*CookieCategoryKind)(nil) +) + +func CookieCategoryKinds() []CookieCategoryKind { + return []CookieCategoryKind{ + CookieCategoryKindNormal, + CookieCategoryKindNecessary, + CookieCategoryKindUncategorised, + } +} + +func (v CookieCategoryKind) IsValid() bool { + switch v { + case + CookieCategoryKindNormal, + CookieCategoryKindNecessary, + CookieCategoryKindUncategorised: + return true + } + + return false +} + +func (v CookieCategoryKind) String() string { + return string(v) +} + +func (v CookieCategoryKind) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *CookieCategoryKind) UnmarshalText(text []byte) error { + val := CookieCategoryKind(text) + if !val.IsValid() { + return fmt.Errorf("invalid CookieCategoryKind value: %q", string(text)) + } + + *v = val + + return nil +} + func (k CookieCategoryKind) IsRequired() bool { return k == CookieCategoryKindNecessary } diff --git a/pkg/coredata/cookie_category_order_field.go b/pkg/coredata/cookie_category_order_field.go index 202d25ff5..a6e157f53 100644 --- a/pkg/coredata/cookie_category_order_field.go +++ b/pkg/coredata/cookie_category_order_field.go @@ -14,7 +14,12 @@ package coredata -import "fmt" +import ( + "encoding" + "fmt" + + "go.probo.inc/probo/pkg/page" +) type CookieCategoryOrderField string @@ -22,6 +27,48 @@ const ( CookieCategoryOrderFieldRank CookieCategoryOrderField = "RANK" ) +var ( + _ page.OrderField = CookieCategoryOrderField("") + _ fmt.Stringer = CookieCategoryOrderField("") + _ encoding.TextMarshaler = CookieCategoryOrderField("") + _ encoding.TextUnmarshaler = (*CookieCategoryOrderField)(nil) +) + +func CookieCategoryOrderFields() []CookieCategoryOrderField { + return []CookieCategoryOrderField{ + CookieCategoryOrderFieldRank, + } +} + +func (v CookieCategoryOrderField) IsValid() bool { + switch v { + case + CookieCategoryOrderFieldRank: + return true + } + + return false +} + +func (v CookieCategoryOrderField) String() string { + return string(v) +} + +func (v CookieCategoryOrderField) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *CookieCategoryOrderField) UnmarshalText(text []byte) error { + val := CookieCategoryOrderField(text) + if !val.IsValid() { + return fmt.Errorf("invalid CookieCategoryOrderField value: %q", string(text)) + } + + *v = val + + return nil +} + func (p CookieCategoryOrderField) Column() string { switch p { case CookieCategoryOrderFieldRank: @@ -30,29 +77,3 @@ func (p CookieCategoryOrderField) Column() string { panic(fmt.Sprintf("unsupported order by: %s", p)) } - -func (p CookieCategoryOrderField) IsValid() bool { - switch p { - case CookieCategoryOrderFieldRank: - return true - } - - return false -} - -func (p CookieCategoryOrderField) String() string { - return string(p) -} - -func (p *CookieCategoryOrderField) UnmarshalText(text []byte) error { - *p = CookieCategoryOrderField(text) - if !p.IsValid() { - return fmt.Errorf("%s is not a valid CookieCategoryOrderField", string(text)) - } - - return nil -} - -func (p CookieCategoryOrderField) MarshalText() ([]byte, error) { - return []byte(p.String()), nil -} diff --git a/pkg/coredata/cookie_consent_action.go b/pkg/coredata/cookie_consent_action.go index 3bc1d9ebe..b45946213 100644 --- a/pkg/coredata/cookie_consent_action.go +++ b/pkg/coredata/cookie_consent_action.go @@ -15,7 +15,7 @@ package coredata import ( - "database/sql/driver" + "encoding" "fmt" ) @@ -29,6 +29,12 @@ const ( CookieConsentActionGPC CookieConsentAction = "GPC" ) +var ( + _ fmt.Stringer = CookieConsentAction("") + _ encoding.TextMarshaler = CookieConsentAction("") + _ encoding.TextUnmarshaler = (*CookieConsentAction)(nil) +) + func CookieConsentActions() []CookieConsentAction { return []CookieConsentAction{ CookieConsentActionAcceptAll, @@ -38,46 +44,34 @@ func CookieConsentActions() []CookieConsentAction { } } -func (a CookieConsentAction) String() string { - return string(a) -} - -func (a *CookieConsentAction) Scan(value any) error { - var v string - - switch val := value.(type) { - case string: - v = val - case []byte: - v = string(val) - default: - return fmt.Errorf("unsupported type for CookieConsentAction: %T", value) - } - - switch CookieConsentAction(v) { - case CookieConsentActionAcceptAll: - *a = CookieConsentActionAcceptAll - case CookieConsentActionRejectAll: - *a = CookieConsentActionRejectAll - case CookieConsentActionCustomize: - *a = CookieConsentActionCustomize - case CookieConsentActionGPC: - *a = CookieConsentActionGPC - default: - return fmt.Errorf("invalid CookieConsentAction value: %q", v) - } - - return nil -} - -func (a CookieConsentAction) Value() (driver.Value, error) { - switch a { - case CookieConsentActionAcceptAll, +func (v CookieConsentAction) IsValid() bool { + switch v { + case + CookieConsentActionAcceptAll, CookieConsentActionRejectAll, CookieConsentActionCustomize, CookieConsentActionGPC: - return string(a), nil - default: - return nil, fmt.Errorf("invalid CookieConsentAction: %s", a) + return true } + + return false +} + +func (v CookieConsentAction) String() string { + return string(v) +} + +func (v CookieConsentAction) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *CookieConsentAction) UnmarshalText(text []byte) error { + val := CookieConsentAction(text) + if !val.IsValid() { + return fmt.Errorf("invalid CookieConsentAction value: %q", string(text)) + } + + *v = val + + return nil } diff --git a/pkg/coredata/cookie_consent_mode.go b/pkg/coredata/cookie_consent_mode.go index dacc87a40..2c873153b 100644 --- a/pkg/coredata/cookie_consent_mode.go +++ b/pkg/coredata/cookie_consent_mode.go @@ -15,7 +15,7 @@ package coredata import ( - "database/sql/driver" + "encoding" "fmt" ) @@ -26,6 +26,12 @@ const ( CookieConsentModeOptOut CookieConsentMode = "OPT_OUT" ) +var ( + _ fmt.Stringer = CookieConsentMode("") + _ encoding.TextMarshaler = CookieConsentMode("") + _ encoding.TextUnmarshaler = (*CookieConsentMode)(nil) +) + func CookieConsentModes() []CookieConsentMode { return []CookieConsentMode{ CookieConsentModeOptIn, @@ -33,40 +39,32 @@ func CookieConsentModes() []CookieConsentMode { } } -func (m CookieConsentMode) String() string { - return string(m) +func (v CookieConsentMode) IsValid() bool { + switch v { + case + CookieConsentModeOptIn, + CookieConsentModeOptOut: + return true + } + + return false } -func (m *CookieConsentMode) Scan(value any) error { - var v string +func (v CookieConsentMode) String() string { + return string(v) +} - switch val := value.(type) { - case string: - v = val - case []byte: - v = string(val) - default: - return fmt.Errorf("unsupported type for CookieConsentMode: %T", value) +func (v CookieConsentMode) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *CookieConsentMode) UnmarshalText(text []byte) error { + val := CookieConsentMode(text) + if !val.IsValid() { + return fmt.Errorf("invalid CookieConsentMode value: %q", string(text)) } - switch CookieConsentMode(v) { - case CookieConsentModeOptIn: - *m = CookieConsentModeOptIn - case CookieConsentModeOptOut: - *m = CookieConsentModeOptOut - default: - return fmt.Errorf("invalid CookieConsentMode value: %q", v) - } + *v = val return nil } - -func (m CookieConsentMode) Value() (driver.Value, error) { - switch m { - case CookieConsentModeOptIn, - CookieConsentModeOptOut: - return string(m), nil - default: - return nil, fmt.Errorf("invalid CookieConsentMode: %s", m) - } -} diff --git a/pkg/coredata/cookie_consent_record_order_field.go b/pkg/coredata/cookie_consent_record_order_field.go index 2ef299a8e..57bd0be9f 100644 --- a/pkg/coredata/cookie_consent_record_order_field.go +++ b/pkg/coredata/cookie_consent_record_order_field.go @@ -14,7 +14,12 @@ package coredata -import "fmt" +import ( + "encoding" + "fmt" + + "go.probo.inc/probo/pkg/page" +) type CookieConsentRecordOrderField string @@ -22,6 +27,48 @@ const ( CookieConsentRecordOrderFieldCreatedAt CookieConsentRecordOrderField = "CREATED_AT" ) +var ( + _ page.OrderField = CookieConsentRecordOrderField("") + _ fmt.Stringer = CookieConsentRecordOrderField("") + _ encoding.TextMarshaler = CookieConsentRecordOrderField("") + _ encoding.TextUnmarshaler = (*CookieConsentRecordOrderField)(nil) +) + +func CookieConsentRecordOrderFields() []CookieConsentRecordOrderField { + return []CookieConsentRecordOrderField{ + CookieConsentRecordOrderFieldCreatedAt, + } +} + +func (v CookieConsentRecordOrderField) IsValid() bool { + switch v { + case + CookieConsentRecordOrderFieldCreatedAt: + return true + } + + return false +} + +func (v CookieConsentRecordOrderField) String() string { + return string(v) +} + +func (v CookieConsentRecordOrderField) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *CookieConsentRecordOrderField) UnmarshalText(text []byte) error { + val := CookieConsentRecordOrderField(text) + if !val.IsValid() { + return fmt.Errorf("invalid CookieConsentRecordOrderField value: %q", string(text)) + } + + *v = val + + return nil +} + func (p CookieConsentRecordOrderField) Column() string { switch p { case CookieConsentRecordOrderFieldCreatedAt: @@ -30,29 +77,3 @@ func (p CookieConsentRecordOrderField) Column() string { panic(fmt.Sprintf("unsupported order by: %s", p)) } - -func (p CookieConsentRecordOrderField) IsValid() bool { - switch p { - case CookieConsentRecordOrderFieldCreatedAt: - return true - } - - return false -} - -func (p CookieConsentRecordOrderField) String() string { - return string(p) -} - -func (p *CookieConsentRecordOrderField) UnmarshalText(text []byte) error { - *p = CookieConsentRecordOrderField(text) - if !p.IsValid() { - return fmt.Errorf("%s is not a valid CookieConsentRecordOrderField", string(text)) - } - - return nil -} - -func (p CookieConsentRecordOrderField) MarshalText() ([]byte, error) { - return []byte(p.String()), nil -} diff --git a/pkg/coredata/cookie_source.go b/pkg/coredata/cookie_source.go index 4b437093c..6291114cf 100644 --- a/pkg/coredata/cookie_source.go +++ b/pkg/coredata/cookie_source.go @@ -15,7 +15,7 @@ package coredata import ( - "database/sql/driver" + "encoding" "fmt" ) @@ -27,6 +27,12 @@ const ( CookieSourceHTTP CookieSource = "HTTP" ) +var ( + _ fmt.Stringer = CookieSource("") + _ encoding.TextMarshaler = CookieSource("") + _ encoding.TextUnmarshaler = (*CookieSource)(nil) +) + func CookieSources() []CookieSource { return []CookieSource{ CookieSourceScript, @@ -35,43 +41,33 @@ func CookieSources() []CookieSource { } } -func (s CookieSource) String() string { - return string(s) +func (v CookieSource) IsValid() bool { + switch v { + case + CookieSourceScript, + CookieSourcePreExisting, + CookieSourceHTTP: + return true + } + + return false } -func (s *CookieSource) Scan(value any) error { - var v string +func (v CookieSource) String() string { + return string(v) +} - switch val := value.(type) { - case string: - v = val - case []byte: - v = string(val) - default: - return fmt.Errorf("unsupported type for CookieSource: %T", value) +func (v CookieSource) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *CookieSource) UnmarshalText(text []byte) error { + val := CookieSource(text) + if !val.IsValid() { + return fmt.Errorf("invalid CookieSource value: %q", string(text)) } - switch CookieSource(v) { - case CookieSourceScript: - *s = CookieSourceScript - case CookieSourcePreExisting: - *s = CookieSourcePreExisting - case CookieSourceHTTP: - *s = CookieSourceHTTP - default: - return fmt.Errorf("invalid CookieSource value: %q", v) - } + *v = val return nil } - -func (s CookieSource) Value() (driver.Value, error) { - switch s { - case CookieSourceScript, - CookieSourcePreExisting, - CookieSourceHTTP: - return string(s), nil - default: - return nil, fmt.Errorf("invalid CookieSource: %s", s) - } -} diff --git a/pkg/coredata/country_code.go b/pkg/coredata/country_code.go index e329c6743..642706715 100644 --- a/pkg/coredata/country_code.go +++ b/pkg/coredata/country_code.go @@ -16,6 +16,7 @@ package coredata import ( "database/sql/driver" + "encoding" "fmt" "strings" ) @@ -276,530 +277,289 @@ const ( CountryCodeZW CountryCode = "ZW" ) -func (ct CountryCode) String() string { - return string(ct) +var ( + _ fmt.Stringer = CountryCode("") + _ encoding.TextMarshaler = CountryCode("") + _ encoding.TextUnmarshaler = (*CountryCode)(nil) +) + +func (v CountryCode) IsValid() bool { + switch v { + case + CountryCodeAD, + CountryCodeAE, + CountryCodeAF, + CountryCodeAG, + CountryCodeAI, + CountryCodeAL, + CountryCodeAM, + CountryCodeAO, + CountryCodeAQ, + CountryCodeAR, + CountryCodeAS, + CountryCodeAT, + CountryCodeAU, + CountryCodeAW, + CountryCodeAX, + CountryCodeAZ, + CountryCodeBA, + CountryCodeBB, + CountryCodeBD, + CountryCodeBE, + CountryCodeBF, + CountryCodeBG, + CountryCodeBH, + CountryCodeBI, + CountryCodeBJ, + CountryCodeBL, + CountryCodeBM, + CountryCodeBN, + CountryCodeBO, + CountryCodeBQ, + CountryCodeBR, + CountryCodeBS, + CountryCodeBT, + CountryCodeBV, + CountryCodeBW, + CountryCodeBY, + CountryCodeBZ, + CountryCodeCA, + CountryCodeCC, + CountryCodeCD, + CountryCodeCF, + CountryCodeCG, + CountryCodeCH, + CountryCodeCI, + CountryCodeCK, + CountryCodeCL, + CountryCodeCM, + CountryCodeCN, + CountryCodeCO, + CountryCodeCR, + CountryCodeCU, + CountryCodeCV, + CountryCodeCW, + CountryCodeCX, + CountryCodeCY, + CountryCodeCZ, + CountryCodeDE, + CountryCodeDJ, + CountryCodeDK, + CountryCodeDM, + CountryCodeDO, + CountryCodeDZ, + CountryCodeEC, + CountryCodeEE, + CountryCodeEG, + CountryCodeEH, + CountryCodeER, + CountryCodeES, + CountryCodeET, + CountryCodeEU, + CountryCodeFI, + CountryCodeFJ, + CountryCodeFK, + CountryCodeFM, + CountryCodeFO, + CountryCodeFR, + CountryCodeGA, + CountryCodeGB, + CountryCodeGD, + CountryCodeGE, + CountryCodeGF, + CountryCodeGG, + CountryCodeGH, + CountryCodeGI, + CountryCodeGL, + CountryCodeGM, + CountryCodeGN, + CountryCodeGP, + CountryCodeGQ, + CountryCodeGR, + CountryCodeGT, + CountryCodeGU, + CountryCodeGW, + CountryCodeGY, + CountryCodeHK, + CountryCodeHM, + CountryCodeHN, + CountryCodeHR, + CountryCodeHT, + CountryCodeHU, + CountryCodeID, + CountryCodeIE, + CountryCodeIL, + CountryCodeIM, + CountryCodeIN, + CountryCodeIO, + CountryCodeIQ, + CountryCodeIR, + CountryCodeIS, + CountryCodeIT, + CountryCodeJE, + CountryCodeJM, + CountryCodeJO, + CountryCodeJP, + CountryCodeKE, + CountryCodeKG, + CountryCodeKH, + CountryCodeKI, + CountryCodeKM, + CountryCodeKN, + CountryCodeKP, + CountryCodeKR, + CountryCodeKW, + CountryCodeKY, + CountryCodeKZ, + CountryCodeLA, + CountryCodeLB, + CountryCodeLC, + CountryCodeLI, + CountryCodeLK, + CountryCodeLR, + CountryCodeLS, + CountryCodeLT, + CountryCodeLU, + CountryCodeLV, + CountryCodeLY, + CountryCodeMA, + CountryCodeMC, + CountryCodeMD, + CountryCodeME, + CountryCodeMF, + CountryCodeMG, + CountryCodeMH, + CountryCodeMK, + CountryCodeML, + CountryCodeMM, + CountryCodeMN, + CountryCodeMO, + CountryCodeMP, + CountryCodeMQ, + CountryCodeMR, + CountryCodeMS, + CountryCodeMT, + CountryCodeMU, + CountryCodeMV, + CountryCodeMW, + CountryCodeMX, + CountryCodeMY, + CountryCodeMZ, + CountryCodeNA, + CountryCodeNC, + CountryCodeNE, + CountryCodeNF, + CountryCodeNG, + CountryCodeNI, + CountryCodeNL, + CountryCodeNO, + CountryCodeNP, + CountryCodeNR, + CountryCodeNU, + CountryCodeNZ, + CountryCodeOM, + CountryCodePA, + CountryCodePE, + CountryCodePF, + CountryCodePG, + CountryCodePH, + CountryCodePK, + CountryCodePL, + CountryCodePM, + CountryCodePN, + CountryCodePR, + CountryCodePS, + CountryCodePT, + CountryCodePW, + CountryCodePY, + CountryCodeQA, + CountryCodeRE, + CountryCodeRO, + CountryCodeRS, + CountryCodeRU, + CountryCodeRW, + CountryCodeSA, + CountryCodeSB, + CountryCodeSC, + CountryCodeSD, + CountryCodeSE, + CountryCodeSG, + CountryCodeSH, + CountryCodeSI, + CountryCodeSJ, + CountryCodeSK, + CountryCodeSL, + CountryCodeSM, + CountryCodeSN, + CountryCodeSO, + CountryCodeSR, + CountryCodeSS, + CountryCodeST, + CountryCodeSV, + CountryCodeSX, + CountryCodeSY, + CountryCodeSZ, + CountryCodeTC, + CountryCodeTD, + CountryCodeTF, + CountryCodeTG, + CountryCodeTH, + CountryCodeTJ, + CountryCodeTK, + CountryCodeTL, + CountryCodeTM, + CountryCodeTN, + CountryCodeTO, + CountryCodeTR, + CountryCodeTT, + CountryCodeTV, + CountryCodeTW, + CountryCodeTZ, + CountryCodeUA, + CountryCodeUG, + CountryCodeUM, + CountryCodeUS, + CountryCodeUY, + CountryCodeUZ, + CountryCodeVA, + CountryCodeVC, + CountryCodeVE, + CountryCodeVG, + CountryCodeVI, + CountryCodeVN, + CountryCodeVU, + CountryCodeWF, + CountryCodeWS, + CountryCodeYE, + CountryCodeYT, + CountryCodeZA, + CountryCodeZM, + CountryCodeZW: + return true + } + + return false } -func (ct *CountryCode) Scan(value any) error { - var s string +func (v CountryCode) String() string { + return string(v) +} - switch v := value.(type) { - case string: - s = v - case []byte: - s = string(v) - default: - return fmt.Errorf("unsupported type for CountryCode: %T", value) +func (v CountryCode) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *CountryCode) UnmarshalText(text []byte) error { + val := CountryCode(text) + if !val.IsValid() { + return fmt.Errorf("invalid CountryCode value: %q", string(text)) } - switch s { - case CountryCodeAD.String(): - *ct = CountryCodeAD - case CountryCodeAE.String(): - *ct = CountryCodeAE - case CountryCodeAF.String(): - *ct = CountryCodeAF - case CountryCodeAG.String(): - *ct = CountryCodeAG - case CountryCodeAI.String(): - *ct = CountryCodeAI - case CountryCodeAL.String(): - *ct = CountryCodeAL - case CountryCodeAM.String(): - *ct = CountryCodeAM - case CountryCodeAO.String(): - *ct = CountryCodeAO - case CountryCodeAQ.String(): - *ct = CountryCodeAQ - case CountryCodeAR.String(): - *ct = CountryCodeAR - case CountryCodeAS.String(): - *ct = CountryCodeAS - case CountryCodeAT.String(): - *ct = CountryCodeAT - case CountryCodeAU.String(): - *ct = CountryCodeAU - case CountryCodeAW.String(): - *ct = CountryCodeAW - case CountryCodeAX.String(): - *ct = CountryCodeAX - case CountryCodeAZ.String(): - *ct = CountryCodeAZ - case CountryCodeBA.String(): - *ct = CountryCodeBA - case CountryCodeBB.String(): - *ct = CountryCodeBB - case CountryCodeBD.String(): - *ct = CountryCodeBD - case CountryCodeBE.String(): - *ct = CountryCodeBE - case CountryCodeBF.String(): - *ct = CountryCodeBF - case CountryCodeBG.String(): - *ct = CountryCodeBG - case CountryCodeBH.String(): - *ct = CountryCodeBH - case CountryCodeBI.String(): - *ct = CountryCodeBI - case CountryCodeBJ.String(): - *ct = CountryCodeBJ - case CountryCodeBL.String(): - *ct = CountryCodeBL - case CountryCodeBM.String(): - *ct = CountryCodeBM - case CountryCodeBN.String(): - *ct = CountryCodeBN - case CountryCodeBO.String(): - *ct = CountryCodeBO - case CountryCodeBQ.String(): - *ct = CountryCodeBQ - case CountryCodeBR.String(): - *ct = CountryCodeBR - case CountryCodeBS.String(): - *ct = CountryCodeBS - case CountryCodeBT.String(): - *ct = CountryCodeBT - case CountryCodeBV.String(): - *ct = CountryCodeBV - case CountryCodeBW.String(): - *ct = CountryCodeBW - case CountryCodeBY.String(): - *ct = CountryCodeBY - case CountryCodeBZ.String(): - *ct = CountryCodeBZ - case CountryCodeCA.String(): - *ct = CountryCodeCA - case CountryCodeCC.String(): - *ct = CountryCodeCC - case CountryCodeCD.String(): - *ct = CountryCodeCD - case CountryCodeCF.String(): - *ct = CountryCodeCF - case CountryCodeCG.String(): - *ct = CountryCodeCG - case CountryCodeCH.String(): - *ct = CountryCodeCH - case CountryCodeCI.String(): - *ct = CountryCodeCI - case CountryCodeCK.String(): - *ct = CountryCodeCK - case CountryCodeCL.String(): - *ct = CountryCodeCL - case CountryCodeCM.String(): - *ct = CountryCodeCM - case CountryCodeCN.String(): - *ct = CountryCodeCN - case CountryCodeCO.String(): - *ct = CountryCodeCO - case CountryCodeCR.String(): - *ct = CountryCodeCR - case CountryCodeCU.String(): - *ct = CountryCodeCU - case CountryCodeCV.String(): - *ct = CountryCodeCV - case CountryCodeCW.String(): - *ct = CountryCodeCW - case CountryCodeCX.String(): - *ct = CountryCodeCX - case CountryCodeCY.String(): - *ct = CountryCodeCY - case CountryCodeCZ.String(): - *ct = CountryCodeCZ - case CountryCodeDE.String(): - *ct = CountryCodeDE - case CountryCodeDJ.String(): - *ct = CountryCodeDJ - case CountryCodeDK.String(): - *ct = CountryCodeDK - case CountryCodeDM.String(): - *ct = CountryCodeDM - case CountryCodeDO.String(): - *ct = CountryCodeDO - case CountryCodeDZ.String(): - *ct = CountryCodeDZ - case CountryCodeEC.String(): - *ct = CountryCodeEC - case CountryCodeEE.String(): - *ct = CountryCodeEE - case CountryCodeEG.String(): - *ct = CountryCodeEG - case CountryCodeEH.String(): - *ct = CountryCodeEH - case CountryCodeER.String(): - *ct = CountryCodeER - case CountryCodeES.String(): - *ct = CountryCodeES - case CountryCodeET.String(): - *ct = CountryCodeET - case CountryCodeEU.String(): - *ct = CountryCodeEU - case CountryCodeFI.String(): - *ct = CountryCodeFI - case CountryCodeFJ.String(): - *ct = CountryCodeFJ - case CountryCodeFK.String(): - *ct = CountryCodeFK - case CountryCodeFM.String(): - *ct = CountryCodeFM - case CountryCodeFO.String(): - *ct = CountryCodeFO - case CountryCodeFR.String(): - *ct = CountryCodeFR - case CountryCodeGA.String(): - *ct = CountryCodeGA - case CountryCodeGB.String(): - *ct = CountryCodeGB - case CountryCodeGD.String(): - *ct = CountryCodeGD - case CountryCodeGE.String(): - *ct = CountryCodeGE - case CountryCodeGF.String(): - *ct = CountryCodeGF - case CountryCodeGG.String(): - *ct = CountryCodeGG - case CountryCodeGH.String(): - *ct = CountryCodeGH - case CountryCodeGI.String(): - *ct = CountryCodeGI - case CountryCodeGL.String(): - *ct = CountryCodeGL - case CountryCodeGM.String(): - *ct = CountryCodeGM - case CountryCodeGN.String(): - *ct = CountryCodeGN - case CountryCodeGP.String(): - *ct = CountryCodeGP - case CountryCodeGQ.String(): - *ct = CountryCodeGQ - case CountryCodeGR.String(): - *ct = CountryCodeGR - case CountryCodeGT.String(): - *ct = CountryCodeGT - case CountryCodeGU.String(): - *ct = CountryCodeGU - case CountryCodeGW.String(): - *ct = CountryCodeGW - case CountryCodeGY.String(): - *ct = CountryCodeGY - case CountryCodeHK.String(): - *ct = CountryCodeHK - case CountryCodeHM.String(): - *ct = CountryCodeHM - case CountryCodeHN.String(): - *ct = CountryCodeHN - case CountryCodeHR.String(): - *ct = CountryCodeHR - case CountryCodeHT.String(): - *ct = CountryCodeHT - case CountryCodeHU.String(): - *ct = CountryCodeHU - case CountryCodeID.String(): - *ct = CountryCodeID - case CountryCodeIE.String(): - *ct = CountryCodeIE - case CountryCodeIL.String(): - *ct = CountryCodeIL - case CountryCodeIM.String(): - *ct = CountryCodeIM - case CountryCodeIN.String(): - *ct = CountryCodeIN - case CountryCodeIO.String(): - *ct = CountryCodeIO - case CountryCodeIQ.String(): - *ct = CountryCodeIQ - case CountryCodeIR.String(): - *ct = CountryCodeIR - case CountryCodeIS.String(): - *ct = CountryCodeIS - case CountryCodeIT.String(): - *ct = CountryCodeIT - case CountryCodeJE.String(): - *ct = CountryCodeJE - case CountryCodeJM.String(): - *ct = CountryCodeJM - case CountryCodeJO.String(): - *ct = CountryCodeJO - case CountryCodeJP.String(): - *ct = CountryCodeJP - case CountryCodeKE.String(): - *ct = CountryCodeKE - case CountryCodeKG.String(): - *ct = CountryCodeKG - case CountryCodeKH.String(): - *ct = CountryCodeKH - case CountryCodeKI.String(): - *ct = CountryCodeKI - case CountryCodeKM.String(): - *ct = CountryCodeKM - case CountryCodeKN.String(): - *ct = CountryCodeKN - case CountryCodeKP.String(): - *ct = CountryCodeKP - case CountryCodeKR.String(): - *ct = CountryCodeKR - case CountryCodeKW.String(): - *ct = CountryCodeKW - case CountryCodeKY.String(): - *ct = CountryCodeKY - case CountryCodeKZ.String(): - *ct = CountryCodeKZ - case CountryCodeLA.String(): - *ct = CountryCodeLA - case CountryCodeLB.String(): - *ct = CountryCodeLB - case CountryCodeLC.String(): - *ct = CountryCodeLC - case CountryCodeLI.String(): - *ct = CountryCodeLI - case CountryCodeLK.String(): - *ct = CountryCodeLK - case CountryCodeLR.String(): - *ct = CountryCodeLR - case CountryCodeLS.String(): - *ct = CountryCodeLS - case CountryCodeLT.String(): - *ct = CountryCodeLT - case CountryCodeLU.String(): - *ct = CountryCodeLU - case CountryCodeLV.String(): - *ct = CountryCodeLV - case CountryCodeLY.String(): - *ct = CountryCodeLY - case CountryCodeMA.String(): - *ct = CountryCodeMA - case CountryCodeMC.String(): - *ct = CountryCodeMC - case CountryCodeMD.String(): - *ct = CountryCodeMD - case CountryCodeME.String(): - *ct = CountryCodeME - case CountryCodeMF.String(): - *ct = CountryCodeMF - case CountryCodeMG.String(): - *ct = CountryCodeMG - case CountryCodeMH.String(): - *ct = CountryCodeMH - case CountryCodeMK.String(): - *ct = CountryCodeMK - case CountryCodeML.String(): - *ct = CountryCodeML - case CountryCodeMM.String(): - *ct = CountryCodeMM - case CountryCodeMN.String(): - *ct = CountryCodeMN - case CountryCodeMO.String(): - *ct = CountryCodeMO - case CountryCodeMP.String(): - *ct = CountryCodeMP - case CountryCodeMQ.String(): - *ct = CountryCodeMQ - case CountryCodeMR.String(): - *ct = CountryCodeMR - case CountryCodeMS.String(): - *ct = CountryCodeMS - case CountryCodeMT.String(): - *ct = CountryCodeMT - case CountryCodeMU.String(): - *ct = CountryCodeMU - case CountryCodeMV.String(): - *ct = CountryCodeMV - case CountryCodeMW.String(): - *ct = CountryCodeMW - case CountryCodeMX.String(): - *ct = CountryCodeMX - case CountryCodeMY.String(): - *ct = CountryCodeMY - case CountryCodeMZ.String(): - *ct = CountryCodeMZ - case CountryCodeNA.String(): - *ct = CountryCodeNA - case CountryCodeNC.String(): - *ct = CountryCodeNC - case CountryCodeNE.String(): - *ct = CountryCodeNE - case CountryCodeNF.String(): - *ct = CountryCodeNF - case CountryCodeNG.String(): - *ct = CountryCodeNG - case CountryCodeNI.String(): - *ct = CountryCodeNI - case CountryCodeNL.String(): - *ct = CountryCodeNL - case CountryCodeNO.String(): - *ct = CountryCodeNO - case CountryCodeNP.String(): - *ct = CountryCodeNP - case CountryCodeNR.String(): - *ct = CountryCodeNR - case CountryCodeNU.String(): - *ct = CountryCodeNU - case CountryCodeNZ.String(): - *ct = CountryCodeNZ - case CountryCodeOM.String(): - *ct = CountryCodeOM - case CountryCodePA.String(): - *ct = CountryCodePA - case CountryCodePE.String(): - *ct = CountryCodePE - case CountryCodePF.String(): - *ct = CountryCodePF - case CountryCodePG.String(): - *ct = CountryCodePG - case CountryCodePH.String(): - *ct = CountryCodePH - case CountryCodePK.String(): - *ct = CountryCodePK - case CountryCodePL.String(): - *ct = CountryCodePL - case CountryCodePM.String(): - *ct = CountryCodePM - case CountryCodePN.String(): - *ct = CountryCodePN - case CountryCodePR.String(): - *ct = CountryCodePR - case CountryCodePS.String(): - *ct = CountryCodePS - case CountryCodePT.String(): - *ct = CountryCodePT - case CountryCodePW.String(): - *ct = CountryCodePW - case CountryCodePY.String(): - *ct = CountryCodePY - case CountryCodeQA.String(): - *ct = CountryCodeQA - case CountryCodeRE.String(): - *ct = CountryCodeRE - case CountryCodeRO.String(): - *ct = CountryCodeRO - case CountryCodeRS.String(): - *ct = CountryCodeRS - case CountryCodeRU.String(): - *ct = CountryCodeRU - case CountryCodeRW.String(): - *ct = CountryCodeRW - case CountryCodeSA.String(): - *ct = CountryCodeSA - case CountryCodeSB.String(): - *ct = CountryCodeSB - case CountryCodeSC.String(): - *ct = CountryCodeSC - case CountryCodeSD.String(): - *ct = CountryCodeSD - case CountryCodeSE.String(): - *ct = CountryCodeSE - case CountryCodeSG.String(): - *ct = CountryCodeSG - case CountryCodeSH.String(): - *ct = CountryCodeSH - case CountryCodeSI.String(): - *ct = CountryCodeSI - case CountryCodeSJ.String(): - *ct = CountryCodeSJ - case CountryCodeSK.String(): - *ct = CountryCodeSK - case CountryCodeSL.String(): - *ct = CountryCodeSL - case CountryCodeSM.String(): - *ct = CountryCodeSM - case CountryCodeSN.String(): - *ct = CountryCodeSN - case CountryCodeSO.String(): - *ct = CountryCodeSO - case CountryCodeSR.String(): - *ct = CountryCodeSR - case CountryCodeSS.String(): - *ct = CountryCodeSS - case CountryCodeST.String(): - *ct = CountryCodeST - case CountryCodeSV.String(): - *ct = CountryCodeSV - case CountryCodeSY.String(): - *ct = CountryCodeSY - case CountryCodeSZ.String(): - *ct = CountryCodeSZ - case CountryCodeTC.String(): - *ct = CountryCodeTC - case CountryCodeTD.String(): - *ct = CountryCodeTD - case CountryCodeTF.String(): - *ct = CountryCodeTF - case CountryCodeTG.String(): - *ct = CountryCodeTG - case CountryCodeTH.String(): - *ct = CountryCodeTH - case CountryCodeTJ.String(): - *ct = CountryCodeTJ - case CountryCodeTK.String(): - *ct = CountryCodeTK - case CountryCodeTL.String(): - *ct = CountryCodeTL - case CountryCodeTM.String(): - *ct = CountryCodeTM - case CountryCodeTN.String(): - *ct = CountryCodeTN - case CountryCodeTO.String(): - *ct = CountryCodeTO - case CountryCodeTR.String(): - *ct = CountryCodeTR - case CountryCodeTT.String(): - *ct = CountryCodeTT - case CountryCodeTV.String(): - *ct = CountryCodeTV - case CountryCodeTW.String(): - *ct = CountryCodeTW - case CountryCodeTZ.String(): - *ct = CountryCodeTZ - case CountryCodeUA.String(): - *ct = CountryCodeUA - case CountryCodeUG.String(): - *ct = CountryCodeUG - case CountryCodeUM.String(): - *ct = CountryCodeUM - case CountryCodeUS.String(): - *ct = CountryCodeUS - case CountryCodeUY.String(): - *ct = CountryCodeUY - case CountryCodeUZ.String(): - *ct = CountryCodeUZ - case CountryCodeVA.String(): - *ct = CountryCodeVA - case CountryCodeVC.String(): - *ct = CountryCodeVC - case CountryCodeVE.String(): - *ct = CountryCodeVE - case CountryCodeVG.String(): - *ct = CountryCodeVG - case CountryCodeVI.String(): - *ct = CountryCodeVI - case CountryCodeVN.String(): - *ct = CountryCodeVN - case CountryCodeVU.String(): - *ct = CountryCodeVU - case CountryCodeWF.String(): - *ct = CountryCodeWF - case CountryCodeWS.String(): - *ct = CountryCodeWS - case CountryCodeYE.String(): - *ct = CountryCodeYE - case CountryCodeYT.String(): - *ct = CountryCodeYT - case CountryCodeZA.String(): - *ct = CountryCodeZA - case CountryCodeZM.String(): - *ct = CountryCodeZM - case CountryCodeZW.String(): - *ct = CountryCodeZW - default: - return fmt.Errorf("invalid CountryCode value: %q", s) - } + *v = val return nil } -func (st CountryCode) Value() (driver.Value, error) { - return st.String(), nil -} - type CountryCodes []CountryCode func (s *CountryCodes) Scan(value any) error { @@ -835,7 +595,7 @@ func (s *CountryCodes) scanFromString(str string) error { } var ct CountryCode - if err := ct.Scan(part); err != nil { + if err := ct.UnmarshalText([]byte(part)); err != nil { return fmt.Errorf("invalid country code in array: %s", part) } diff --git a/pkg/coredata/custom_domain_order_field.go b/pkg/coredata/custom_domain_order_field.go index c41280deb..635dff567 100644 --- a/pkg/coredata/custom_domain_order_field.go +++ b/pkg/coredata/custom_domain_order_field.go @@ -14,7 +14,12 @@ package coredata -import "fmt" +import ( + "encoding" + "fmt" + + "go.probo.inc/probo/pkg/page" +) type CustomDomainOrderField string @@ -24,6 +29,52 @@ const ( CustomDomainOrderFieldUpdatedAt CustomDomainOrderField = "UPDATED_AT" ) +var ( + _ page.OrderField = CustomDomainOrderField("") + _ fmt.Stringer = CustomDomainOrderField("") + _ encoding.TextMarshaler = CustomDomainOrderField("") + _ encoding.TextUnmarshaler = (*CustomDomainOrderField)(nil) +) + +func CustomDomainOrderFields() []CustomDomainOrderField { + return []CustomDomainOrderField{ + CustomDomainOrderFieldCreatedAt, + CustomDomainOrderFieldDomain, + CustomDomainOrderFieldUpdatedAt, + } +} + +func (v CustomDomainOrderField) IsValid() bool { + switch v { + case + CustomDomainOrderFieldCreatedAt, + CustomDomainOrderFieldDomain, + CustomDomainOrderFieldUpdatedAt: + return true + } + + return false +} + +func (v CustomDomainOrderField) String() string { + return string(v) +} + +func (v CustomDomainOrderField) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *CustomDomainOrderField) UnmarshalText(text []byte) error { + val := CustomDomainOrderField(text) + if !val.IsValid() { + return fmt.Errorf("invalid CustomDomainOrderField value: %q", string(text)) + } + + *v = val + + return nil +} + func (f CustomDomainOrderField) Column() string { switch f { case CustomDomainOrderFieldCreatedAt: @@ -36,7 +87,3 @@ func (f CustomDomainOrderField) Column() string { panic(fmt.Sprintf("unsupported order by: %s", f)) } } - -func (f CustomDomainOrderField) String() string { - return string(f) -} diff --git a/pkg/coredata/custom_domain_ssl_status.go b/pkg/coredata/custom_domain_ssl_status.go index 795d5a51a..ad884c87a 100644 --- a/pkg/coredata/custom_domain_ssl_status.go +++ b/pkg/coredata/custom_domain_ssl_status.go @@ -15,7 +15,7 @@ package coredata import ( - "database/sql/driver" + "encoding" "fmt" ) @@ -30,46 +30,53 @@ const ( CustomDomainSSLStatusFailed CustomDomainSSLStatus = "FAILED" ) -func (s CustomDomainSSLStatus) MarshalText() ([]byte, error) { - return []byte(s.String()), nil +var ( + _ fmt.Stringer = CustomDomainSSLStatus("") + _ encoding.TextMarshaler = CustomDomainSSLStatus("") + _ encoding.TextUnmarshaler = (*CustomDomainSSLStatus)(nil) +) + +func CustomDomainSSLStatuses() []CustomDomainSSLStatus { + return []CustomDomainSSLStatus{ + CustomDomainSSLStatusPending, + CustomDomainSSLStatusProvisioning, + CustomDomainSSLStatusActive, + CustomDomainSSLStatusRenewing, + CustomDomainSSLStatusExpired, + CustomDomainSSLStatusFailed, + } } -func (s *CustomDomainSSLStatus) UnmarshalText(data []byte) error { - val := string(data) - - switch val { - case CustomDomainSSLStatusPending.String(): - *s = CustomDomainSSLStatusPending - case CustomDomainSSLStatusProvisioning.String(): - *s = CustomDomainSSLStatusProvisioning - case CustomDomainSSLStatusActive.String(): - *s = CustomDomainSSLStatusActive - case CustomDomainSSLStatusRenewing.String(): - *s = CustomDomainSSLStatusRenewing - case CustomDomainSSLStatusExpired.String(): - *s = CustomDomainSSLStatusExpired - case CustomDomainSSLStatusFailed.String(): - *s = CustomDomainSSLStatusFailed - default: - return fmt.Errorf("invalid CustomDomainSSLStatus value: %q", val) +func (v CustomDomainSSLStatus) IsValid() bool { + switch v { + case + CustomDomainSSLStatusPending, + CustomDomainSSLStatusProvisioning, + CustomDomainSSLStatusActive, + CustomDomainSSLStatusRenewing, + CustomDomainSSLStatusExpired, + CustomDomainSSLStatusFailed: + return true } + return false +} + +func (v CustomDomainSSLStatus) String() string { + return string(v) +} + +func (v CustomDomainSSLStatus) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *CustomDomainSSLStatus) UnmarshalText(text []byte) error { + val := CustomDomainSSLStatus(text) + if !val.IsValid() { + return fmt.Errorf("invalid CustomDomainSSLStatus value: %q", string(text)) + } + + *v = val + return nil } - -func (s CustomDomainSSLStatus) String() string { - return string(s) -} - -func (s *CustomDomainSSLStatus) Scan(value any) error { - val, ok := value.(string) - if !ok { - return fmt.Errorf("invalid scan source for CustomDomainSSLStatus, expected string got %T", value) - } - - return s.UnmarshalText([]byte(val)) -} - -func (s CustomDomainSSLStatus) Value() (driver.Value, error) { - return s.String(), nil -} diff --git a/pkg/coredata/custom_domain_verification_status.go b/pkg/coredata/custom_domain_verification_status.go index dda216b56..cff860207 100644 --- a/pkg/coredata/custom_domain_verification_status.go +++ b/pkg/coredata/custom_domain_verification_status.go @@ -14,6 +14,11 @@ package coredata +import ( + "encoding" + "fmt" +) + type CustomDomainVerificationStatus string const ( @@ -21,3 +26,48 @@ const ( CustomDomainVerificationStatusVerified CustomDomainVerificationStatus = "VERIFIED" CustomDomainVerificationStatusFailed CustomDomainVerificationStatus = "FAILED" ) + +var ( + _ fmt.Stringer = CustomDomainVerificationStatus("") + _ encoding.TextMarshaler = CustomDomainVerificationStatus("") + _ encoding.TextUnmarshaler = (*CustomDomainVerificationStatus)(nil) +) + +func CustomDomainVerificationStatuses() []CustomDomainVerificationStatus { + return []CustomDomainVerificationStatus{ + CustomDomainVerificationStatusPending, + CustomDomainVerificationStatusVerified, + CustomDomainVerificationStatusFailed, + } +} + +func (v CustomDomainVerificationStatus) IsValid() bool { + switch v { + case + CustomDomainVerificationStatusPending, + CustomDomainVerificationStatusVerified, + CustomDomainVerificationStatusFailed: + return true + } + + return false +} + +func (v CustomDomainVerificationStatus) String() string { + return string(v) +} + +func (v CustomDomainVerificationStatus) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *CustomDomainVerificationStatus) UnmarshalText(text []byte) error { + val := CustomDomainVerificationStatus(text) + if !val.IsValid() { + return fmt.Errorf("invalid CustomDomainVerificationStatus value: %q", string(text)) + } + + *v = val + + return nil +} diff --git a/pkg/coredata/data_classification.go b/pkg/coredata/data_classification.go index 18bebd31f..78ee9ea15 100644 --- a/pkg/coredata/data_classification.go +++ b/pkg/coredata/data_classification.go @@ -14,6 +14,11 @@ package coredata +import ( + "encoding" + "fmt" +) + type DataClassification string const ( @@ -23,6 +28,12 @@ const ( DataClassificationSecret DataClassification = "SECRET" ) +var ( + _ fmt.Stringer = DataClassification("") + _ encoding.TextMarshaler = DataClassification("") + _ encoding.TextUnmarshaler = (*DataClassification)(nil) +) + func DataClassifications() []DataClassification { return []DataClassification{ DataClassificationPublic, @@ -31,3 +42,35 @@ func DataClassifications() []DataClassification { DataClassificationSecret, } } + +func (v DataClassification) IsValid() bool { + switch v { + case + DataClassificationPublic, + DataClassificationInternal, + DataClassificationConfidential, + DataClassificationSecret: + return true + } + + return false +} + +func (v DataClassification) String() string { + return string(v) +} + +func (v DataClassification) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *DataClassification) UnmarshalText(text []byte) error { + val := DataClassification(text) + if !val.IsValid() { + return fmt.Errorf("invalid DataClassification value: %q", string(text)) + } + + *v = val + + return nil +} diff --git a/pkg/coredata/data_protection_impact_assessment_order_field.go b/pkg/coredata/data_protection_impact_assessment_order_field.go index b6506719c..4634b3e90 100644 --- a/pkg/coredata/data_protection_impact_assessment_order_field.go +++ b/pkg/coredata/data_protection_impact_assessment_order_field.go @@ -14,7 +14,12 @@ package coredata -import "fmt" +import ( + "encoding" + "fmt" + + "go.probo.inc/probo/pkg/page" +) type DataProtectionImpactAssessmentOrderField string @@ -22,25 +27,48 @@ const ( DataProtectionImpactAssessmentOrderFieldCreatedAt DataProtectionImpactAssessmentOrderField = "CREATED_AT" ) +var ( + _ page.OrderField = DataProtectionImpactAssessmentOrderField("") + _ fmt.Stringer = DataProtectionImpactAssessmentOrderField("") + _ encoding.TextMarshaler = DataProtectionImpactAssessmentOrderField("") + _ encoding.TextUnmarshaler = (*DataProtectionImpactAssessmentOrderField)(nil) +) + +func DataProtectionImpactAssessmentOrderFields() []DataProtectionImpactAssessmentOrderField { + return []DataProtectionImpactAssessmentOrderField{ + DataProtectionImpactAssessmentOrderFieldCreatedAt, + } +} + +func (v DataProtectionImpactAssessmentOrderField) IsValid() bool { + switch v { + case + DataProtectionImpactAssessmentOrderFieldCreatedAt: + return true + } + + return false +} + +func (v DataProtectionImpactAssessmentOrderField) String() string { + return string(v) +} + +func (v DataProtectionImpactAssessmentOrderField) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *DataProtectionImpactAssessmentOrderField) UnmarshalText(text []byte) error { + val := DataProtectionImpactAssessmentOrderField(text) + if !val.IsValid() { + return fmt.Errorf("invalid DataProtectionImpactAssessmentOrderField value: %q", string(text)) + } + + *v = val + + return nil +} + func (p DataProtectionImpactAssessmentOrderField) Column() string { return string(p) } - -func (p DataProtectionImpactAssessmentOrderField) String() string { - return string(p) -} - -func (p DataProtectionImpactAssessmentOrderField) MarshalText() ([]byte, error) { - return []byte(p.String()), nil -} - -func (p *DataProtectionImpactAssessmentOrderField) UnmarshalText(text []byte) error { - val := string(text) - switch val { - case string(DataProtectionImpactAssessmentOrderFieldCreatedAt): - *p = DataProtectionImpactAssessmentOrderFieldCreatedAt - return nil - } - - return fmt.Errorf("invalid DataProtectionImpactAssessmentOrderField value: %q", val) -} diff --git a/pkg/coredata/data_protection_impact_assessment_residual_risk.go b/pkg/coredata/data_protection_impact_assessment_residual_risk.go index 28ec0770a..920f2396a 100644 --- a/pkg/coredata/data_protection_impact_assessment_residual_risk.go +++ b/pkg/coredata/data_protection_impact_assessment_residual_risk.go @@ -15,7 +15,7 @@ package coredata import ( - "database/sql/driver" + "encoding" "fmt" ) @@ -27,6 +27,12 @@ const ( DataProtectionImpactAssessmentResidualRiskHigh DataProtectionImpactAssessmentResidualRisk = "HIGH" ) +var ( + _ fmt.Stringer = DataProtectionImpactAssessmentResidualRisk("") + _ encoding.TextMarshaler = DataProtectionImpactAssessmentResidualRisk("") + _ encoding.TextUnmarshaler = (*DataProtectionImpactAssessmentResidualRisk)(nil) +) + func DataProtectionImpactAssessmentResidualRisks() []DataProtectionImpactAssessmentResidualRisk { return []DataProtectionImpactAssessmentResidualRisk{ DataProtectionImpactAssessmentResidualRiskLow, @@ -35,36 +41,33 @@ func DataProtectionImpactAssessmentResidualRisks() []DataProtectionImpactAssessm } } -func (p DataProtectionImpactAssessmentResidualRisk) String() string { - return string(p) +func (v DataProtectionImpactAssessmentResidualRisk) IsValid() bool { + switch v { + case + DataProtectionImpactAssessmentResidualRiskLow, + DataProtectionImpactAssessmentResidualRiskMedium, + DataProtectionImpactAssessmentResidualRiskHigh: + return true + } + + return false } -func (p *DataProtectionImpactAssessmentResidualRisk) Scan(value any) error { - var s string +func (v DataProtectionImpactAssessmentResidualRisk) String() string { + return string(v) +} - switch v := value.(type) { - case string: - s = v - case []byte: - s = string(v) - default: - return fmt.Errorf("unsupported type for DataProtectionImpactAssessmentResidualRisk: %T", value) +func (v DataProtectionImpactAssessmentResidualRisk) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *DataProtectionImpactAssessmentResidualRisk) UnmarshalText(text []byte) error { + val := DataProtectionImpactAssessmentResidualRisk(text) + if !val.IsValid() { + return fmt.Errorf("invalid DataProtectionImpactAssessmentResidualRisk value: %q", string(text)) } - switch s { - case "LOW": - *p = DataProtectionImpactAssessmentResidualRiskLow - case "MEDIUM": - *p = DataProtectionImpactAssessmentResidualRiskMedium - case "HIGH": - *p = DataProtectionImpactAssessmentResidualRiskHigh - default: - return fmt.Errorf("invalid DataProtectionImpactAssessmentResidualRisk value: %q", s) - } + *v = val return nil } - -func (p DataProtectionImpactAssessmentResidualRisk) Value() (driver.Value, error) { - return p.String(), nil -} diff --git a/pkg/coredata/data_sensitivity.go b/pkg/coredata/data_sensitivity.go index 1ed703c3d..3cb11fe2b 100644 --- a/pkg/coredata/data_sensitivity.go +++ b/pkg/coredata/data_sensitivity.go @@ -15,8 +15,7 @@ package coredata import ( - "database/sql/driver" - "encoding/json" + "encoding" "fmt" ) @@ -30,6 +29,12 @@ const ( DataSensitivityCritical DataSensitivity = "CRITICAL" ) +var ( + _ fmt.Stringer = DataSensitivity("") + _ encoding.TextMarshaler = DataSensitivity("") + _ encoding.TextUnmarshaler = (*DataSensitivity)(nil) +) + func DataSensitivities() []DataSensitivity { return []DataSensitivity{ DataSensitivityNone, @@ -40,86 +45,35 @@ func DataSensitivities() []DataSensitivity { } } -func (i DataSensitivity) String() string { - return string(i) +func (v DataSensitivity) IsValid() bool { + switch v { + case + DataSensitivityNone, + DataSensitivityLow, + DataSensitivityMedium, + DataSensitivityHigh, + DataSensitivityCritical: + return true + } + + return false } -func (i *DataSensitivity) Scan(value any) error { - switch v := value.(type) { - case string: - switch v { - case "NONE": - *i = DataSensitivityNone - case "LOW": - *i = DataSensitivityLow - case "MEDIUM": - *i = DataSensitivityMedium - case "HIGH": - *i = DataSensitivityHigh - case "CRITICAL": - *i = DataSensitivityCritical - default: - return fmt.Errorf("invalid DataSensitivity value: %q", v) - } - default: - return fmt.Errorf("unsupported type for DataSensitivity: %T", value) - } - - return nil -} - -func (i DataSensitivity) Value() (driver.Value, error) { - return i.String(), nil -} - -func (i DataSensitivity) MarshalJSON() ([]byte, error) { - return json.Marshal(i.String()) -} - -func (i *DataSensitivity) UnmarshalJSON(data []byte) error { - var s string - if err := json.Unmarshal(data, &s); err != nil { - return err - } - - switch s { - case "NONE": - *i = DataSensitivityNone - case "LOW": - *i = DataSensitivityLow - case "MEDIUM": - *i = DataSensitivityMedium - case "HIGH": - *i = DataSensitivityHigh - case "CRITICAL": - *i = DataSensitivityCritical - default: - return fmt.Errorf("invalid DataSensitivity value: %q", s) - } - - return nil -} - -func (i *DataSensitivity) UnmarshalText(text []byte) error { - var s string - if err := json.Unmarshal(text, &s); err != nil { - return err - } - - switch s { - case "NONE": - *i = DataSensitivityNone - case "LOW": - *i = DataSensitivityLow - case "MEDIUM": - *i = DataSensitivityMedium - case "HIGH": - *i = DataSensitivityHigh - case "CRITICAL": - *i = DataSensitivityCritical - default: - return fmt.Errorf("invalid DataSensitivity value: %q", s) +func (v DataSensitivity) String() string { + return string(v) +} + +func (v DataSensitivity) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *DataSensitivity) UnmarshalText(text []byte) error { + val := DataSensitivity(text) + if !val.IsValid() { + return fmt.Errorf("invalid DataSensitivity value: %q", string(text)) } + *v = val + return nil } diff --git a/pkg/coredata/datum_order_field.go b/pkg/coredata/datum_order_field.go index 2e30ec6e6..1f9ec1f57 100644 --- a/pkg/coredata/datum_order_field.go +++ b/pkg/coredata/datum_order_field.go @@ -15,7 +15,10 @@ package coredata import ( + "encoding" "fmt" + + "go.probo.inc/probo/pkg/page" ) type DatumOrderField string @@ -26,27 +29,52 @@ const ( DatumOrderFieldDataClassification DatumOrderField = "DATA_CLASSIFICATION" ) +var ( + _ page.OrderField = DatumOrderField("") + _ fmt.Stringer = DatumOrderField("") + _ encoding.TextMarshaler = DatumOrderField("") + _ encoding.TextUnmarshaler = (*DatumOrderField)(nil) +) + +func DatumOrderFields() []DatumOrderField { + return []DatumOrderField{ + DatumOrderFieldCreatedAt, + DatumOrderFieldName, + DatumOrderFieldDataClassification, + } +} + +func (v DatumOrderField) IsValid() bool { + switch v { + case + DatumOrderFieldCreatedAt, + DatumOrderFieldName, + DatumOrderFieldDataClassification: + return true + } + + return false +} + +func (v DatumOrderField) String() string { + return string(v) +} + +func (v DatumOrderField) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *DatumOrderField) UnmarshalText(text []byte) error { + val := DatumOrderField(text) + if !val.IsValid() { + return fmt.Errorf("invalid DatumOrderField value: %q", string(text)) + } + + *v = val + + return nil +} + func (p DatumOrderField) Column() string { return string(p) } - -func (p DatumOrderField) String() string { - return string(p) -} - -func (p DatumOrderField) MarshalText() ([]byte, error) { - return []byte(p.String()), nil -} - -func (p *DatumOrderField) UnmarshalText(text []byte) error { - val := string(text) - switch val { - case string(DatumOrderFieldCreatedAt), - string(DatumOrderFieldName), - string(DatumOrderFieldDataClassification): - *p = DatumOrderField(val) - return nil - } - - return fmt.Errorf("invalid DatumOrderField value: %q", val) -} diff --git a/pkg/coredata/document_classification.go b/pkg/coredata/document_classification.go index 6d30eb565..c40fc9016 100644 --- a/pkg/coredata/document_classification.go +++ b/pkg/coredata/document_classification.go @@ -15,7 +15,7 @@ package coredata import ( - "database/sql/driver" + "encoding" "fmt" ) @@ -28,6 +28,12 @@ const ( DocumentClassificationSecret DocumentClassification = "SECRET" ) +var ( + _ fmt.Stringer = DocumentClassification("") + _ encoding.TextMarshaler = DocumentClassification("") + _ encoding.TextUnmarshaler = (*DocumentClassification)(nil) +) + func DocumentClassifications() []DocumentClassification { return []DocumentClassification{ DocumentClassificationPublic, @@ -37,44 +43,37 @@ func DocumentClassifications() []DocumentClassification { } } -func (dc DocumentClassification) String() string { - switch dc { - case DocumentClassificationPublic: - return "PUBLIC" - case DocumentClassificationInternal: - return "INTERNAL" - case DocumentClassificationConfidential: - return "CONFIDENTIAL" - case DocumentClassificationSecret: - return "SECRET" +func (v DocumentClassification) IsValid() bool { + switch v { + case + DocumentClassificationPublic, + DocumentClassificationInternal, + DocumentClassificationConfidential, + DocumentClassificationSecret: + return true } - panic(fmt.Errorf("invalid DocumentClassification value: %s", string(dc))) + return false } -// Scan implements the sql.Scanner interface for database deserialization. -func (dc *DocumentClassification) Scan(value any) error { - if value == nil { - return nil +func (v DocumentClassification) String() string { + return string(v) +} + +func (v DocumentClassification) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *DocumentClassification) UnmarshalText(text []byte) error { + val := DocumentClassification(text) + if !val.IsValid() { + return fmt.Errorf("invalid DocumentClassification value: %q", string(text)) } - var sv string - - switch v := value.(type) { - case string: - sv = v - case []byte: - sv = string(v) - default: - return fmt.Errorf("cannot scan DocumentClassification: expected string or []byte, got %T", value) - } - - *dc = DocumentClassification(sv) + *v = val return nil } +// Scan implements the sql.Scanner interface for database deserialization. // Value implements the driver.Valuer interface for database serialization. -func (dc DocumentClassification) Value() (driver.Value, error) { - return string(dc), nil -} diff --git a/pkg/coredata/document_order_field.go b/pkg/coredata/document_order_field.go index 47d145f1c..cf9f44b8e 100644 --- a/pkg/coredata/document_order_field.go +++ b/pkg/coredata/document_order_field.go @@ -14,7 +14,12 @@ package coredata -import "fmt" +import ( + "encoding" + "fmt" + + "go.probo.inc/probo/pkg/page" +) type ( DocumentOrderField string @@ -27,6 +32,54 @@ const ( DocumentOrderFieldDocumentType DocumentOrderField = "DOCUMENT_TYPE" ) +var ( + _ page.OrderField = DocumentOrderField("") + _ fmt.Stringer = DocumentOrderField("") + _ encoding.TextMarshaler = DocumentOrderField("") + _ encoding.TextUnmarshaler = (*DocumentOrderField)(nil) +) + +func DocumentOrderFields() []DocumentOrderField { + return []DocumentOrderField{ + DocumentOrderFieldCreatedAt, + DocumentOrderFieldUpdatedAt, + DocumentOrderFieldTitle, + DocumentOrderFieldDocumentType, + } +} + +func (v DocumentOrderField) IsValid() bool { + switch v { + case + DocumentOrderFieldCreatedAt, + DocumentOrderFieldUpdatedAt, + DocumentOrderFieldTitle, + DocumentOrderFieldDocumentType: + return true + } + + return false +} + +func (v DocumentOrderField) String() string { + return string(v) +} + +func (v DocumentOrderField) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *DocumentOrderField) UnmarshalText(text []byte) error { + val := DocumentOrderField(text) + if !val.IsValid() { + return fmt.Errorf("invalid DocumentOrderField value: %q", string(text)) + } + + *v = val + + return nil +} + func (p DocumentOrderField) Column() string { switch p { case DocumentOrderFieldCreatedAt: @@ -41,32 +94,3 @@ func (p DocumentOrderField) Column() string { panic(fmt.Sprintf("unsupported order by: %s", p)) } - -func (p DocumentOrderField) IsValid() bool { - switch p { - case DocumentOrderFieldCreatedAt, - DocumentOrderFieldUpdatedAt, - DocumentOrderFieldTitle, - DocumentOrderFieldDocumentType: - return true - } - - return false -} - -func (p DocumentOrderField) String() string { - return string(p) -} - -func (p DocumentOrderField) MarshalText() ([]byte, error) { - return []byte(p.String()), nil -} - -func (p *DocumentOrderField) UnmarshalText(text []byte) error { - *p = DocumentOrderField(text) - if !p.IsValid() { - return fmt.Errorf("%s is not a valid DocumentOrderField", string(text)) - } - - return nil -} diff --git a/pkg/coredata/document_status.go b/pkg/coredata/document_status.go index 285d6f559..cc88e85e6 100644 --- a/pkg/coredata/document_status.go +++ b/pkg/coredata/document_status.go @@ -15,7 +15,7 @@ package coredata import ( - "database/sql/driver" + "encoding" "fmt" ) @@ -26,39 +26,45 @@ const ( DocumentStatusArchived DocumentStatus = "ARCHIVED" ) -func (s DocumentStatus) IsValid() bool { - switch s { - case DocumentStatusActive, DocumentStatusArchived: +var ( + _ fmt.Stringer = DocumentStatus("") + _ encoding.TextMarshaler = DocumentStatus("") + _ encoding.TextUnmarshaler = (*DocumentStatus)(nil) +) + +func DocumentStatuses() []DocumentStatus { + return []DocumentStatus{ + DocumentStatusActive, + DocumentStatusArchived, + } +} + +func (v DocumentStatus) IsValid() bool { + switch v { + case + DocumentStatusActive, + DocumentStatusArchived: return true } return false } -func (s DocumentStatus) String() string { return string(s) } +func (v DocumentStatus) String() string { + return string(v) +} -func (s *DocumentStatus) UnmarshalText(text []byte) error { - *s = DocumentStatus(text) - if !s.IsValid() { - return fmt.Errorf("%s is not a valid DocumentStatus", string(text)) +func (v DocumentStatus) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *DocumentStatus) UnmarshalText(text []byte) error { + val := DocumentStatus(text) + if !val.IsValid() { + return fmt.Errorf("invalid DocumentStatus value: %q", string(text)) } + *v = val + return nil } - -func (s DocumentStatus) MarshalText() ([]byte, error) { - return []byte(s.String()), nil -} - -func (s *DocumentStatus) Scan(value any) error { - val, ok := value.(string) - if !ok { - return fmt.Errorf("invalid scan source for DocumentStatus, expected string got %T", value) - } - - return s.UnmarshalText([]byte(val)) -} - -func (s DocumentStatus) Value() (driver.Value, error) { - return s.String(), nil -} diff --git a/pkg/coredata/document_type.go b/pkg/coredata/document_type.go index 740ffa294..6cf90d310 100644 --- a/pkg/coredata/document_type.go +++ b/pkg/coredata/document_type.go @@ -15,7 +15,7 @@ package coredata import ( - "database/sql/driver" + "encoding" "fmt" ) @@ -36,6 +36,12 @@ const ( DocumentTypeStatementOfApplicability DocumentType = "STATEMENT_OF_APPLICABILITY" ) +var ( + _ fmt.Stringer = DocumentType("") + _ encoding.TextMarshaler = DocumentType("") + _ encoding.TextUnmarshaler = (*DocumentType)(nil) +) + func DocumentTypes() []DocumentType { return []DocumentType{ DocumentTypeOther, @@ -51,54 +57,40 @@ func DocumentTypes() []DocumentType { } } -func (dt DocumentType) MarshalText() ([]byte, error) { - return []byte(dt.String()), nil +func (v DocumentType) IsValid() bool { + switch v { + case + DocumentTypeOther, + DocumentTypeGovernance, + DocumentTypePolicy, + DocumentTypeProcedure, + DocumentTypePlan, + DocumentTypeRegister, + DocumentTypeRecord, + DocumentTypeReport, + DocumentTypeTemplate, + DocumentTypeStatementOfApplicability: + return true + } + + return false } -func (dt *DocumentType) UnmarshalText(data []byte) error { - val := string(data) +func (v DocumentType) String() string { + return string(v) +} - switch val { - case DocumentTypeOther.String(): - *dt = DocumentTypeOther - case DocumentTypeGovernance.String(): - *dt = DocumentTypeGovernance - case DocumentTypePolicy.String(): - *dt = DocumentTypePolicy - case DocumentTypeProcedure.String(): - *dt = DocumentTypeProcedure - case DocumentTypePlan.String(): - *dt = DocumentTypePlan - case DocumentTypeRegister.String(): - *dt = DocumentTypeRegister - case DocumentTypeRecord.String(): - *dt = DocumentTypeRecord - case DocumentTypeReport.String(): - *dt = DocumentTypeReport - case DocumentTypeTemplate.String(): - *dt = DocumentTypeTemplate - case DocumentTypeStatementOfApplicability.String(): - *dt = DocumentTypeStatementOfApplicability - default: - return fmt.Errorf("invalid DocumentType value: %q", val) +func (v DocumentType) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *DocumentType) UnmarshalText(text []byte) error { + val := DocumentType(text) + if !val.IsValid() { + return fmt.Errorf("invalid DocumentType value: %q", string(text)) } + *v = val + return nil } - -func (dt DocumentType) String() string { - return string(dt) -} - -func (dt *DocumentType) Scan(value any) error { - val, ok := value.(string) - if !ok { - return fmt.Errorf("invalid scan source for DocumentType, expected string got %T", value) - } - - return dt.UnmarshalText([]byte(val)) -} - -func (dt DocumentType) Value() (driver.Value, error) { - return dt.String(), nil -} diff --git a/pkg/coredata/document_version_approval_decision_order_field.go b/pkg/coredata/document_version_approval_decision_order_field.go index 9cf688e67..764949e9f 100644 --- a/pkg/coredata/document_version_approval_decision_order_field.go +++ b/pkg/coredata/document_version_approval_decision_order_field.go @@ -14,7 +14,12 @@ package coredata -import "fmt" +import ( + "encoding" + "fmt" + + "go.probo.inc/probo/pkg/page" +) type ( DocumentVersionApprovalDecisionOrderField string @@ -24,6 +29,48 @@ const ( DocumentVersionApprovalDecisionOrderFieldCreatedAt DocumentVersionApprovalDecisionOrderField = "CREATED_AT" ) +var ( + _ page.OrderField = DocumentVersionApprovalDecisionOrderField("") + _ fmt.Stringer = DocumentVersionApprovalDecisionOrderField("") + _ encoding.TextMarshaler = DocumentVersionApprovalDecisionOrderField("") + _ encoding.TextUnmarshaler = (*DocumentVersionApprovalDecisionOrderField)(nil) +) + +func DocumentVersionApprovalDecisionOrderFields() []DocumentVersionApprovalDecisionOrderField { + return []DocumentVersionApprovalDecisionOrderField{ + DocumentVersionApprovalDecisionOrderFieldCreatedAt, + } +} + +func (v DocumentVersionApprovalDecisionOrderField) IsValid() bool { + switch v { + case + DocumentVersionApprovalDecisionOrderFieldCreatedAt: + return true + } + + return false +} + +func (v DocumentVersionApprovalDecisionOrderField) String() string { + return string(v) +} + +func (v DocumentVersionApprovalDecisionOrderField) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *DocumentVersionApprovalDecisionOrderField) UnmarshalText(text []byte) error { + val := DocumentVersionApprovalDecisionOrderField(text) + if !val.IsValid() { + return fmt.Errorf("invalid DocumentVersionApprovalDecisionOrderField value: %q", string(text)) + } + + *v = val + + return nil +} + func (e DocumentVersionApprovalDecisionOrderField) Column() string { switch e { case DocumentVersionApprovalDecisionOrderFieldCreatedAt: @@ -32,27 +79,3 @@ func (e DocumentVersionApprovalDecisionOrderField) Column() string { panic(fmt.Sprintf("unsupported order by: %s", e)) } - -func (e DocumentVersionApprovalDecisionOrderField) IsValid() bool { - switch e { - case DocumentVersionApprovalDecisionOrderFieldCreatedAt: - return true - } - - return false -} - -func (e DocumentVersionApprovalDecisionOrderField) String() string { return string(e) } - -func (e *DocumentVersionApprovalDecisionOrderField) UnmarshalText(text []byte) error { - *e = DocumentVersionApprovalDecisionOrderField(text) - if !e.IsValid() { - return fmt.Errorf("%s is not a valid DocumentVersionApprovalDecisionOrderField", string(text)) - } - - return nil -} - -func (e DocumentVersionApprovalDecisionOrderField) MarshalText() ([]byte, error) { - return []byte(e.String()), nil -} diff --git a/pkg/coredata/document_version_approval_decision_state.go b/pkg/coredata/document_version_approval_decision_state.go index 36e2405d9..e7d73a412 100644 --- a/pkg/coredata/document_version_approval_decision_state.go +++ b/pkg/coredata/document_version_approval_decision_state.go @@ -16,6 +16,7 @@ package coredata import ( "database/sql/driver" + "encoding" "fmt" "strings" ) @@ -32,61 +33,44 @@ const ( DocumentVersionApprovalDecisionStateVoided DocumentVersionApprovalDecisionState = "VOIDED" ) -func (s DocumentVersionApprovalDecisionState) MarshalText() ([]byte, error) { - return []byte(s.String()), nil +var ( + _ fmt.Stringer = DocumentVersionApprovalDecisionState("") + _ encoding.TextMarshaler = DocumentVersionApprovalDecisionState("") + _ encoding.TextUnmarshaler = (*DocumentVersionApprovalDecisionState)(nil) +) + +func (v DocumentVersionApprovalDecisionState) IsValid() bool { + switch v { + case + DocumentVersionApprovalDecisionStatePending, + DocumentVersionApprovalDecisionStateApproved, + DocumentVersionApprovalDecisionStateRejected, + DocumentVersionApprovalDecisionStateVoided: + return true + } + + return false } -func (s *DocumentVersionApprovalDecisionState) UnmarshalText(data []byte) error { - val := string(data) +func (v DocumentVersionApprovalDecisionState) String() string { + return string(v) +} - switch val { - case DocumentVersionApprovalDecisionStatePending.String(): - *s = DocumentVersionApprovalDecisionStatePending - case DocumentVersionApprovalDecisionStateApproved.String(): - *s = DocumentVersionApprovalDecisionStateApproved - case DocumentVersionApprovalDecisionStateRejected.String(): - *s = DocumentVersionApprovalDecisionStateRejected - case DocumentVersionApprovalDecisionStateVoided.String(): - *s = DocumentVersionApprovalDecisionStateVoided - default: - return fmt.Errorf("invalid DocumentVersionApprovalDecisionState value: %q", val) +func (v DocumentVersionApprovalDecisionState) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *DocumentVersionApprovalDecisionState) UnmarshalText(text []byte) error { + val := DocumentVersionApprovalDecisionState(text) + if !val.IsValid() { + return fmt.Errorf("invalid DocumentVersionApprovalDecisionState value: %q", string(text)) } + *v = val + return nil } -func (s DocumentVersionApprovalDecisionState) String() string { - var val string - - switch s { - case DocumentVersionApprovalDecisionStatePending: - val = "PENDING" - case DocumentVersionApprovalDecisionStateApproved: - val = "APPROVED" - case DocumentVersionApprovalDecisionStateRejected: - val = "REJECTED" - case DocumentVersionApprovalDecisionStateVoided: - val = "VOIDED" - default: - panic(fmt.Errorf("invalid DocumentVersionApprovalDecisionState value: %q", string(s))) - } - - return val -} - -func (s *DocumentVersionApprovalDecisionState) Scan(value any) error { - val, ok := value.(string) - if !ok { - return fmt.Errorf("invalid scan source for DocumentVersionApprovalDecisionState, expected string got %T", value) - } - - return s.UnmarshalText([]byte(val)) -} - -func (s DocumentVersionApprovalDecisionState) Value() (driver.Value, error) { - return s.String(), nil -} - func (states DocumentVersionApprovalDecisionStates) Value() (driver.Value, error) { if len(states) == 0 { return nil, nil diff --git a/pkg/coredata/document_version_approval_quorum_order_field.go b/pkg/coredata/document_version_approval_quorum_order_field.go index 67f998004..eebfedc26 100644 --- a/pkg/coredata/document_version_approval_quorum_order_field.go +++ b/pkg/coredata/document_version_approval_quorum_order_field.go @@ -14,7 +14,12 @@ package coredata -import "fmt" +import ( + "encoding" + "fmt" + + "go.probo.inc/probo/pkg/page" +) type ( DocumentVersionApprovalQuorumOrderField string @@ -24,6 +29,48 @@ const ( DocumentVersionApprovalQuorumOrderFieldCreatedAt DocumentVersionApprovalQuorumOrderField = "CREATED_AT" ) +var ( + _ page.OrderField = DocumentVersionApprovalQuorumOrderField("") + _ fmt.Stringer = DocumentVersionApprovalQuorumOrderField("") + _ encoding.TextMarshaler = DocumentVersionApprovalQuorumOrderField("") + _ encoding.TextUnmarshaler = (*DocumentVersionApprovalQuorumOrderField)(nil) +) + +func DocumentVersionApprovalQuorumOrderFields() []DocumentVersionApprovalQuorumOrderField { + return []DocumentVersionApprovalQuorumOrderField{ + DocumentVersionApprovalQuorumOrderFieldCreatedAt, + } +} + +func (v DocumentVersionApprovalQuorumOrderField) IsValid() bool { + switch v { + case + DocumentVersionApprovalQuorumOrderFieldCreatedAt: + return true + } + + return false +} + +func (v DocumentVersionApprovalQuorumOrderField) String() string { + return string(v) +} + +func (v DocumentVersionApprovalQuorumOrderField) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *DocumentVersionApprovalQuorumOrderField) UnmarshalText(text []byte) error { + val := DocumentVersionApprovalQuorumOrderField(text) + if !val.IsValid() { + return fmt.Errorf("invalid DocumentVersionApprovalQuorumOrderField value: %q", string(text)) + } + + *v = val + + return nil +} + func (e DocumentVersionApprovalQuorumOrderField) Column() string { switch e { case DocumentVersionApprovalQuorumOrderFieldCreatedAt: @@ -32,27 +79,3 @@ func (e DocumentVersionApprovalQuorumOrderField) Column() string { panic(fmt.Sprintf("unsupported order by: %s", e)) } - -func (e DocumentVersionApprovalQuorumOrderField) IsValid() bool { - switch e { - case DocumentVersionApprovalQuorumOrderFieldCreatedAt: - return true - } - - return false -} - -func (e DocumentVersionApprovalQuorumOrderField) String() string { return string(e) } - -func (e *DocumentVersionApprovalQuorumOrderField) UnmarshalText(text []byte) error { - *e = DocumentVersionApprovalQuorumOrderField(text) - if !e.IsValid() { - return fmt.Errorf("%s is not a valid DocumentVersionApprovalQuorumOrderField", string(text)) - } - - return nil -} - -func (e DocumentVersionApprovalQuorumOrderField) MarshalText() ([]byte, error) { - return []byte(e.String()), nil -} diff --git a/pkg/coredata/document_version_approval_quorum_status.go b/pkg/coredata/document_version_approval_quorum_status.go index 6309953fb..137f03adc 100644 --- a/pkg/coredata/document_version_approval_quorum_status.go +++ b/pkg/coredata/document_version_approval_quorum_status.go @@ -15,7 +15,7 @@ package coredata import ( - "database/sql/driver" + "encoding" "fmt" ) @@ -28,57 +28,49 @@ const ( DocumentVersionApprovalQuorumStatusVoided DocumentVersionApprovalQuorumStatus = "VOIDED" ) -func (s DocumentVersionApprovalQuorumStatus) MarshalText() ([]byte, error) { - return []byte(s.String()), nil +var ( + _ fmt.Stringer = DocumentVersionApprovalQuorumStatus("") + _ encoding.TextMarshaler = DocumentVersionApprovalQuorumStatus("") + _ encoding.TextUnmarshaler = (*DocumentVersionApprovalQuorumStatus)(nil) +) + +func DocumentVersionApprovalQuorumStatuses() []DocumentVersionApprovalQuorumStatus { + return []DocumentVersionApprovalQuorumStatus{ + DocumentVersionApprovalQuorumStatusPending, + DocumentVersionApprovalQuorumStatusApproved, + DocumentVersionApprovalQuorumStatusRejected, + DocumentVersionApprovalQuorumStatusVoided, + } } -func (s *DocumentVersionApprovalQuorumStatus) UnmarshalText(data []byte) error { - val := string(data) - - switch val { - case DocumentVersionApprovalQuorumStatusPending.String(): - *s = DocumentVersionApprovalQuorumStatusPending - case DocumentVersionApprovalQuorumStatusApproved.String(): - *s = DocumentVersionApprovalQuorumStatusApproved - case DocumentVersionApprovalQuorumStatusRejected.String(): - *s = DocumentVersionApprovalQuorumStatusRejected - case DocumentVersionApprovalQuorumStatusVoided.String(): - *s = DocumentVersionApprovalQuorumStatusVoided - default: - return fmt.Errorf("invalid DocumentVersionApprovalQuorumStatus value: %q", val) +func (v DocumentVersionApprovalQuorumStatus) IsValid() bool { + switch v { + case + DocumentVersionApprovalQuorumStatusPending, + DocumentVersionApprovalQuorumStatusApproved, + DocumentVersionApprovalQuorumStatusRejected, + DocumentVersionApprovalQuorumStatusVoided: + return true } + return false +} + +func (v DocumentVersionApprovalQuorumStatus) String() string { + return string(v) +} + +func (v DocumentVersionApprovalQuorumStatus) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *DocumentVersionApprovalQuorumStatus) UnmarshalText(text []byte) error { + val := DocumentVersionApprovalQuorumStatus(text) + if !val.IsValid() { + return fmt.Errorf("invalid DocumentVersionApprovalQuorumStatus value: %q", string(text)) + } + + *v = val + return nil } - -func (s DocumentVersionApprovalQuorumStatus) String() string { - var val string - - switch s { - case DocumentVersionApprovalQuorumStatusPending: - val = "PENDING" - case DocumentVersionApprovalQuorumStatusApproved: - val = "APPROVED" - case DocumentVersionApprovalQuorumStatusRejected: - val = "REJECTED" - case DocumentVersionApprovalQuorumStatusVoided: - val = "VOIDED" - default: - panic(fmt.Errorf("invalid DocumentVersionApprovalQuorumStatus value: %q", string(s))) - } - - return val -} - -func (s *DocumentVersionApprovalQuorumStatus) Scan(value any) error { - val, ok := value.(string) - if !ok { - return fmt.Errorf("invalid scan source for DocumentVersionApprovalQuorumStatus, expected string got %T", value) - } - - return s.UnmarshalText([]byte(val)) -} - -func (s DocumentVersionApprovalQuorumStatus) Value() (driver.Value, error) { - return s.String(), nil -} diff --git a/pkg/coredata/document_version_filter.go b/pkg/coredata/document_version_filter.go index 3349a9a0d..47a37e377 100644 --- a/pkg/coredata/document_version_filter.go +++ b/pkg/coredata/document_version_filter.go @@ -15,6 +15,9 @@ package coredata import ( + "encoding" + "fmt" + "github.com/jackc/pgx/v5" "go.probo.inc/probo/pkg/gid" ) @@ -26,6 +29,49 @@ const ( EmployeeFilterModeApproval EmployeeFilterMode = "approval" ) +var ( + _ fmt.Stringer = EmployeeFilterMode("") + _ encoding.TextMarshaler = EmployeeFilterMode("") + _ encoding.TextUnmarshaler = (*EmployeeFilterMode)(nil) +) + +func EmployeeFilterModes() []EmployeeFilterMode { + return []EmployeeFilterMode{ + EmployeeFilterModeSignature, + EmployeeFilterModeApproval, + } +} + +func (v EmployeeFilterMode) IsValid() bool { + switch v { + case + EmployeeFilterModeSignature, + EmployeeFilterModeApproval: + return true + } + + return false +} + +func (v EmployeeFilterMode) String() string { + return string(v) +} + +func (v EmployeeFilterMode) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *EmployeeFilterMode) UnmarshalText(text []byte) error { + val := EmployeeFilterMode(text) + if !val.IsValid() { + return fmt.Errorf("invalid EmployeeFilterMode value: %q", string(text)) + } + + *v = val + + return nil +} + type ( DocumentVersionFilter struct { statuses []DocumentVersionStatus diff --git a/pkg/coredata/document_version_order_field.go b/pkg/coredata/document_version_order_field.go index 5e0a00ca7..ca9f5d15e 100644 --- a/pkg/coredata/document_version_order_field.go +++ b/pkg/coredata/document_version_order_field.go @@ -14,6 +14,13 @@ package coredata +import ( + "encoding" + "fmt" + + "go.probo.inc/probo/pkg/page" +) + type ( DocumentVersionOrderField string ) @@ -22,19 +29,48 @@ const ( DocumentVersionOrderFieldCreatedAt DocumentVersionOrderField = "CREATED_AT" ) +var ( + _ page.OrderField = DocumentVersionOrderField("") + _ fmt.Stringer = DocumentVersionOrderField("") + _ encoding.TextMarshaler = DocumentVersionOrderField("") + _ encoding.TextUnmarshaler = (*DocumentVersionOrderField)(nil) +) + +func DocumentVersionOrderFields() []DocumentVersionOrderField { + return []DocumentVersionOrderField{ + DocumentVersionOrderFieldCreatedAt, + } +} + +func (v DocumentVersionOrderField) IsValid() bool { + switch v { + case + DocumentVersionOrderFieldCreatedAt: + return true + } + + return false +} + +func (v DocumentVersionOrderField) String() string { + return string(v) +} + +func (v DocumentVersionOrderField) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *DocumentVersionOrderField) UnmarshalText(text []byte) error { + val := DocumentVersionOrderField(text) + if !val.IsValid() { + return fmt.Errorf("invalid DocumentVersionOrderField value: %q", string(text)) + } + + *v = val + + return nil +} + func (p DocumentVersionOrderField) Column() string { return string(p) } - -func (p DocumentVersionOrderField) String() string { - return string(p) -} - -func (p DocumentVersionOrderField) MarshalText() ([]byte, error) { - return []byte(p.String()), nil -} - -func (p *DocumentVersionOrderField) UnmarshalText(text []byte) error { - *p = DocumentVersionOrderField(text) - return nil -} diff --git a/pkg/coredata/document_version_orientation.go b/pkg/coredata/document_version_orientation.go index cf8739bb6..5358f65e9 100644 --- a/pkg/coredata/document_version_orientation.go +++ b/pkg/coredata/document_version_orientation.go @@ -15,7 +15,7 @@ package coredata import ( - "database/sql/driver" + "encoding" "fmt" ) @@ -28,6 +28,12 @@ const ( DocumentVersionOrientationLandscape DocumentVersionOrientation = "LANDSCAPE" ) +var ( + _ fmt.Stringer = DocumentVersionOrientation("") + _ encoding.TextMarshaler = DocumentVersionOrientation("") + _ encoding.TextUnmarshaler = (*DocumentVersionOrientation)(nil) +) + func DocumentVersionOrientations() []DocumentVersionOrientation { return []DocumentVersionOrientation{ DocumentVersionOrientationPortrait, @@ -35,38 +41,32 @@ func DocumentVersionOrientations() []DocumentVersionOrientation { } } -func (o DocumentVersionOrientation) MarshalText() ([]byte, error) { - return []byte(o.String()), nil +func (v DocumentVersionOrientation) IsValid() bool { + switch v { + case + DocumentVersionOrientationPortrait, + DocumentVersionOrientationLandscape: + return true + } + + return false } -func (o *DocumentVersionOrientation) UnmarshalText(data []byte) error { - val := string(data) +func (v DocumentVersionOrientation) String() string { + return string(v) +} - switch val { - case DocumentVersionOrientationPortrait.String(): - *o = DocumentVersionOrientationPortrait - case DocumentVersionOrientationLandscape.String(): - *o = DocumentVersionOrientationLandscape - default: - return fmt.Errorf("invalid DocumentVersionOrientation value: %q", val) +func (v DocumentVersionOrientation) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *DocumentVersionOrientation) UnmarshalText(text []byte) error { + val := DocumentVersionOrientation(text) + if !val.IsValid() { + return fmt.Errorf("invalid DocumentVersionOrientation value: %q", string(text)) } + *v = val + return nil } - -func (o DocumentVersionOrientation) String() string { - return string(o) -} - -func (o *DocumentVersionOrientation) Scan(value any) error { - val, ok := value.(string) - if !ok { - return fmt.Errorf("invalid scan source for DocumentVersionOrientation, expected string got %T", value) - } - - return o.UnmarshalText([]byte(val)) -} - -func (o DocumentVersionOrientation) Value() (driver.Value, error) { - return o.String(), nil -} diff --git a/pkg/coredata/document_version_signature_order_field.go b/pkg/coredata/document_version_signature_order_field.go index f6394048d..5cc816572 100644 --- a/pkg/coredata/document_version_signature_order_field.go +++ b/pkg/coredata/document_version_signature_order_field.go @@ -14,6 +14,13 @@ package coredata +import ( + "encoding" + "fmt" + + "go.probo.inc/probo/pkg/page" +) + type ( DocumentVersionSignatureOrderField string ) @@ -23,19 +30,50 @@ const ( DocumentVersionSignatureOrderFieldSignedAt DocumentVersionSignatureOrderField = "SIGNED_AT" ) +var ( + _ page.OrderField = DocumentVersionSignatureOrderField("") + _ fmt.Stringer = DocumentVersionSignatureOrderField("") + _ encoding.TextMarshaler = DocumentVersionSignatureOrderField("") + _ encoding.TextUnmarshaler = (*DocumentVersionSignatureOrderField)(nil) +) + +func DocumentVersionSignatureOrderFields() []DocumentVersionSignatureOrderField { + return []DocumentVersionSignatureOrderField{ + DocumentVersionSignatureOrderFieldCreatedAt, + DocumentVersionSignatureOrderFieldSignedAt, + } +} + +func (v DocumentVersionSignatureOrderField) IsValid() bool { + switch v { + case + DocumentVersionSignatureOrderFieldCreatedAt, + DocumentVersionSignatureOrderFieldSignedAt: + return true + } + + return false +} + +func (v DocumentVersionSignatureOrderField) String() string { + return string(v) +} + +func (v DocumentVersionSignatureOrderField) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *DocumentVersionSignatureOrderField) UnmarshalText(text []byte) error { + val := DocumentVersionSignatureOrderField(text) + if !val.IsValid() { + return fmt.Errorf("invalid DocumentVersionSignatureOrderField value: %q", string(text)) + } + + *v = val + + return nil +} + func (p DocumentVersionSignatureOrderField) Column() string { return string(p) } - -func (p DocumentVersionSignatureOrderField) String() string { - return string(p) -} - -func (p DocumentVersionSignatureOrderField) MarshalText() ([]byte, error) { - return []byte(p.String()), nil -} - -func (p *DocumentVersionSignatureOrderField) UnmarshalText(text []byte) error { - *p = DocumentVersionSignatureOrderField(text) - return nil -} diff --git a/pkg/coredata/document_version_signature_state.go b/pkg/coredata/document_version_signature_state.go index d5bc8d598..9fc87064c 100644 --- a/pkg/coredata/document_version_signature_state.go +++ b/pkg/coredata/document_version_signature_state.go @@ -16,6 +16,7 @@ package coredata import ( "database/sql/driver" + "encoding" "fmt" "strings" ) @@ -30,53 +31,42 @@ const ( DocumentVersionSignatureStateSigned DocumentVersionSignatureState = "SIGNED" ) -func (pvs DocumentVersionSignatureState) MarshalText() ([]byte, error) { - return []byte(pvs.String()), nil +var ( + _ fmt.Stringer = DocumentVersionSignatureState("") + _ encoding.TextMarshaler = DocumentVersionSignatureState("") + _ encoding.TextUnmarshaler = (*DocumentVersionSignatureState)(nil) +) + +func (v DocumentVersionSignatureState) IsValid() bool { + switch v { + case + DocumentVersionSignatureStateRequested, + DocumentVersionSignatureStateSigned: + return true + } + + return false } -func (pvs *DocumentVersionSignatureState) UnmarshalText(data []byte) error { - val := string(data) +func (v DocumentVersionSignatureState) String() string { + return string(v) +} - switch val { - case DocumentVersionSignatureStateRequested.String(): - *pvs = DocumentVersionSignatureStateRequested - case DocumentVersionSignatureStateSigned.String(): - *pvs = DocumentVersionSignatureStateSigned - default: - return fmt.Errorf("invalid DocumentVersionSignatureState value: %q", val) +func (v DocumentVersionSignatureState) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *DocumentVersionSignatureState) UnmarshalText(text []byte) error { + val := DocumentVersionSignatureState(text) + if !val.IsValid() { + return fmt.Errorf("invalid DocumentVersionSignatureState value: %q", string(text)) } + *v = val + return nil } -func (pvs DocumentVersionSignatureState) String() string { - var val string - - switch pvs { - case DocumentVersionSignatureStateRequested: - val = "REQUESTED" - case DocumentVersionSignatureStateSigned: - val = "SIGNED" - default: - panic(fmt.Errorf("invalid DocumentVersionSignatureState value: %q", string(pvs))) - } - - return val -} - -func (pvs *DocumentVersionSignatureState) Scan(value any) error { - val, ok := value.(string) - if !ok { - return fmt.Errorf("invalid scan source for DocumentVersionSignatureState, expected string got %T", value) - } - - return pvs.UnmarshalText([]byte(val)) -} - -func (pvs DocumentVersionSignatureState) Value() (driver.Value, error) { - return pvs.String(), nil -} - func (states DocumentVersionSignatureStates) Value() (driver.Value, error) { if len(states) == 0 { return nil, nil diff --git a/pkg/coredata/document_version_status.go b/pkg/coredata/document_version_status.go index 9c71517d1..a3888c270 100644 --- a/pkg/coredata/document_version_status.go +++ b/pkg/coredata/document_version_status.go @@ -15,7 +15,7 @@ package coredata import ( - "database/sql/driver" + "encoding" "fmt" ) @@ -29,49 +29,47 @@ const ( DocumentVersionStatusPublished DocumentVersionStatus = "PUBLISHED" ) -func (ps DocumentVersionStatus) MarshalText() ([]byte, error) { - return []byte(ps.String()), nil +var ( + _ fmt.Stringer = DocumentVersionStatus("") + _ encoding.TextMarshaler = DocumentVersionStatus("") + _ encoding.TextUnmarshaler = (*DocumentVersionStatus)(nil) +) + +func DocumentVersionStatuses() []DocumentVersionStatus { + return []DocumentVersionStatus{ + DocumentVersionStatusDraft, + DocumentVersionStatusPendingApproval, + DocumentVersionStatusPublished, + } } -func (ps *DocumentVersionStatus) UnmarshalText(data []byte) error { - val := string(data) - - switch val { - case DocumentVersionStatusDraft.String(): - *ps = DocumentVersionStatusDraft - case DocumentVersionStatusPendingApproval.String(): - *ps = DocumentVersionStatusPendingApproval - case DocumentVersionStatusPublished.String(): - *ps = DocumentVersionStatusPublished - default: - return fmt.Errorf("invalid DocumentVersionStatus value: %q", val) +func (v DocumentVersionStatus) IsValid() bool { + switch v { + case + DocumentVersionStatusDraft, + DocumentVersionStatusPendingApproval, + DocumentVersionStatusPublished: + return true } + return false +} + +func (v DocumentVersionStatus) String() string { + return string(v) +} + +func (v DocumentVersionStatus) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *DocumentVersionStatus) UnmarshalText(text []byte) error { + val := DocumentVersionStatus(text) + if !val.IsValid() { + return fmt.Errorf("invalid DocumentVersionStatus value: %q", string(text)) + } + + *v = val + return nil } - -func (ps DocumentVersionStatus) String() string { - switch ps { - case DocumentVersionStatusDraft: - return "DRAFT" - case DocumentVersionStatusPendingApproval: - return "PENDING_APPROVAL" - case DocumentVersionStatusPublished: - return "PUBLISHED" - default: - panic(fmt.Errorf("invalid DocumentVersionStatus value: %q", string(ps))) - } -} - -func (ps *DocumentVersionStatus) Scan(value any) error { - val, ok := value.(string) - if !ok { - return fmt.Errorf("invalid scan source for DocumentVersionStatus, expected string got %T", value) - } - - return ps.UnmarshalText([]byte(val)) -} - -func (ps DocumentVersionStatus) Value() (driver.Value, error) { - return ps.String(), nil -} diff --git a/pkg/coredata/document_write_mode.go b/pkg/coredata/document_write_mode.go index c3ff0d3c4..afd2d9208 100644 --- a/pkg/coredata/document_write_mode.go +++ b/pkg/coredata/document_write_mode.go @@ -14,7 +14,10 @@ package coredata -import "fmt" +import ( + "encoding" + "fmt" +) type ( DocumentWriteMode string @@ -25,26 +28,45 @@ const ( DocumentWriteModeGenerated DocumentWriteMode = "GENERATED" ) -func (e DocumentWriteMode) IsValid() bool { - switch e { - case DocumentWriteModeAuthored, DocumentWriteModeGenerated: +var ( + _ fmt.Stringer = DocumentWriteMode("") + _ encoding.TextMarshaler = DocumentWriteMode("") + _ encoding.TextUnmarshaler = (*DocumentWriteMode)(nil) +) + +func DocumentWriteModes() []DocumentWriteMode { + return []DocumentWriteMode{ + DocumentWriteModeAuthored, + DocumentWriteModeGenerated, + } +} + +func (v DocumentWriteMode) IsValid() bool { + switch v { + case + DocumentWriteModeAuthored, + DocumentWriteModeGenerated: return true } return false } -func (e DocumentWriteMode) String() string { return string(e) } +func (v DocumentWriteMode) String() string { + return string(v) +} -func (e *DocumentWriteMode) UnmarshalText(text []byte) error { - *e = DocumentWriteMode(text) - if !e.IsValid() { - return fmt.Errorf("%s is not a valid DocumentWriteMode", string(text)) +func (v DocumentWriteMode) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *DocumentWriteMode) UnmarshalText(text []byte) error { + val := DocumentWriteMode(text) + if !val.IsValid() { + return fmt.Errorf("invalid DocumentWriteMode value: %q", string(text)) } + *v = val + return nil } - -func (e DocumentWriteMode) MarshalText() ([]byte, error) { - return []byte(e.String()), nil -} diff --git a/pkg/coredata/electronic_signature_document_type.go b/pkg/coredata/electronic_signature_document_type.go index 7621ba0be..563b4fb40 100644 --- a/pkg/coredata/electronic_signature_document_type.go +++ b/pkg/coredata/electronic_signature_document_type.go @@ -15,7 +15,7 @@ package coredata import ( - "database/sql/driver" + "encoding" "fmt" ) @@ -45,6 +45,12 @@ const ( ESignProcessConsentText = "By typing my full name and clicking Accept, I consent to sign this document electronically and agree that my electronic signature has the same legal validity as a handwritten signature." ) +var ( + _ fmt.Stringer = ElectronicSignatureDocumentType("") + _ encoding.TextMarshaler = ElectronicSignatureDocumentType("") + _ encoding.TextUnmarshaler = (*ElectronicSignatureDocumentType)(nil) +) + func ElectronicSignatureDocumentTypes() []ElectronicSignatureDocumentType { return []ElectronicSignatureDocumentType{ ElectronicSignatureDocumentTypeNDA, @@ -67,72 +73,51 @@ func ElectronicSignatureDocumentTypes() []ElectronicSignatureDocumentType { } } -func (dt ElectronicSignatureDocumentType) MarshalText() ([]byte, error) { - return []byte(dt.String()), nil +func (v ElectronicSignatureDocumentType) IsValid() bool { + switch v { + case + ElectronicSignatureDocumentTypeNDA, + ElectronicSignatureDocumentTypeDPA, + ElectronicSignatureDocumentTypeMSA, + ElectronicSignatureDocumentTypeSOW, + ElectronicSignatureDocumentTypeSLA, + ElectronicSignatureDocumentTypeTOS, + ElectronicSignatureDocumentTypePrivacyPolicy, + ElectronicSignatureDocumentTypeGovernance, + ElectronicSignatureDocumentTypePolicy, + ElectronicSignatureDocumentTypeProcedure, + ElectronicSignatureDocumentTypePlan, + ElectronicSignatureDocumentTypeRegister, + ElectronicSignatureDocumentTypeRecord, + ElectronicSignatureDocumentTypeReport, + ElectronicSignatureDocumentTypeTemplate, + ElectronicSignatureDocumentTypeStatementOfApplicability, + ElectronicSignatureDocumentTypeOther: + return true + } + + return false } -func (dt *ElectronicSignatureDocumentType) UnmarshalText(data []byte) error { - val := string(data) +func (v ElectronicSignatureDocumentType) String() string { + return string(v) +} - switch val { - case ElectronicSignatureDocumentTypeNDA.String(): - *dt = ElectronicSignatureDocumentTypeNDA - case ElectronicSignatureDocumentTypeDPA.String(): - *dt = ElectronicSignatureDocumentTypeDPA - case ElectronicSignatureDocumentTypeMSA.String(): - *dt = ElectronicSignatureDocumentTypeMSA - case ElectronicSignatureDocumentTypeSOW.String(): - *dt = ElectronicSignatureDocumentTypeSOW - case ElectronicSignatureDocumentTypeSLA.String(): - *dt = ElectronicSignatureDocumentTypeSLA - case ElectronicSignatureDocumentTypeTOS.String(): - *dt = ElectronicSignatureDocumentTypeTOS - case ElectronicSignatureDocumentTypePrivacyPolicy.String(): - *dt = ElectronicSignatureDocumentTypePrivacyPolicy - case ElectronicSignatureDocumentTypeGovernance.String(): - *dt = ElectronicSignatureDocumentTypeGovernance - case ElectronicSignatureDocumentTypePolicy.String(): - *dt = ElectronicSignatureDocumentTypePolicy - case ElectronicSignatureDocumentTypeProcedure.String(): - *dt = ElectronicSignatureDocumentTypeProcedure - case ElectronicSignatureDocumentTypePlan.String(): - *dt = ElectronicSignatureDocumentTypePlan - case ElectronicSignatureDocumentTypeRegister.String(): - *dt = ElectronicSignatureDocumentTypeRegister - case ElectronicSignatureDocumentTypeRecord.String(): - *dt = ElectronicSignatureDocumentTypeRecord - case ElectronicSignatureDocumentTypeReport.String(): - *dt = ElectronicSignatureDocumentTypeReport - case ElectronicSignatureDocumentTypeTemplate.String(): - *dt = ElectronicSignatureDocumentTypeTemplate - case ElectronicSignatureDocumentTypeStatementOfApplicability.String(): - *dt = ElectronicSignatureDocumentTypeStatementOfApplicability - case ElectronicSignatureDocumentTypeOther.String(): - *dt = ElectronicSignatureDocumentTypeOther - default: - return fmt.Errorf("cannot unmarshal ElectronicSignatureDocumentType: invalid value %q", val) +func (v ElectronicSignatureDocumentType) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *ElectronicSignatureDocumentType) UnmarshalText(text []byte) error { + val := ElectronicSignatureDocumentType(text) + if !val.IsValid() { + return fmt.Errorf("invalid ElectronicSignatureDocumentType value: %q", string(text)) } + *v = val + return nil } -func (dt ElectronicSignatureDocumentType) String() string { - return string(dt) -} - -func (dt *ElectronicSignatureDocumentType) Scan(value any) error { - val, ok := value.(string) - if !ok { - return fmt.Errorf("cannot scan ElectronicSignatureDocumentType: expected string, got %T", value) - } - - return dt.UnmarshalText([]byte(val)) -} - -func (dt ElectronicSignatureDocumentType) Value() (driver.Value, error) { - return dt.String(), nil -} - func (dt ElectronicSignatureDocumentType) DisplayName() string { switch dt { case ElectronicSignatureDocumentTypeNDA: diff --git a/pkg/coredata/electronic_signature_event_source.go b/pkg/coredata/electronic_signature_event_source.go index 92a561090..46d8a293a 100644 --- a/pkg/coredata/electronic_signature_event_source.go +++ b/pkg/coredata/electronic_signature_event_source.go @@ -15,7 +15,7 @@ package coredata import ( - "database/sql/driver" + "encoding" "fmt" ) @@ -28,38 +28,45 @@ const ( ElectronicSignatureEventSourceServer ElectronicSignatureEventSource = "SERVER" ) -func (s ElectronicSignatureEventSource) MarshalText() ([]byte, error) { - return []byte(s.String()), nil +var ( + _ fmt.Stringer = ElectronicSignatureEventSource("") + _ encoding.TextMarshaler = ElectronicSignatureEventSource("") + _ encoding.TextUnmarshaler = (*ElectronicSignatureEventSource)(nil) +) + +func ElectronicSignatureEventSources() []ElectronicSignatureEventSource { + return []ElectronicSignatureEventSource{ + ElectronicSignatureEventSourceClient, + ElectronicSignatureEventSourceServer, + } } -func (s *ElectronicSignatureEventSource) UnmarshalText(data []byte) error { - val := string(data) - - switch val { - case ElectronicSignatureEventSourceClient.String(): - *s = ElectronicSignatureEventSourceClient - case ElectronicSignatureEventSourceServer.String(): - *s = ElectronicSignatureEventSourceServer - default: - return fmt.Errorf("invalid ElectronicSignatureEventSource value: %q", val) +func (v ElectronicSignatureEventSource) IsValid() bool { + switch v { + case + ElectronicSignatureEventSourceClient, + ElectronicSignatureEventSourceServer: + return true } + return false +} + +func (v ElectronicSignatureEventSource) String() string { + return string(v) +} + +func (v ElectronicSignatureEventSource) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *ElectronicSignatureEventSource) UnmarshalText(text []byte) error { + val := ElectronicSignatureEventSource(text) + if !val.IsValid() { + return fmt.Errorf("invalid ElectronicSignatureEventSource value: %q", string(text)) + } + + *v = val + return nil } - -func (s ElectronicSignatureEventSource) String() string { - return string(s) -} - -func (s *ElectronicSignatureEventSource) Scan(value any) error { - val, ok := value.(string) - if !ok { - return fmt.Errorf("invalid scan source for ElectronicSignatureEventSource, expected string got %T", value) - } - - return s.UnmarshalText([]byte(val)) -} - -func (s ElectronicSignatureEventSource) Value() (driver.Value, error) { - return s.String(), nil -} diff --git a/pkg/coredata/electronic_signature_event_type.go b/pkg/coredata/electronic_signature_event_type.go index 1a5bd55da..e1a8dd750 100644 --- a/pkg/coredata/electronic_signature_event_type.go +++ b/pkg/coredata/electronic_signature_event_type.go @@ -15,7 +15,7 @@ package coredata import ( - "database/sql/driver" + "encoding" "fmt" ) @@ -35,58 +35,59 @@ const ( ElectronicSignatureEventTypeProcessingError ElectronicSignatureEventType = "PROCESSING_ERROR" ) -func (t ElectronicSignatureEventType) MarshalText() ([]byte, error) { - return []byte(t.String()), nil +var ( + _ fmt.Stringer = ElectronicSignatureEventType("") + _ encoding.TextMarshaler = ElectronicSignatureEventType("") + _ encoding.TextUnmarshaler = (*ElectronicSignatureEventType)(nil) +) + +func ElectronicSignatureEventTypes() []ElectronicSignatureEventType { + return []ElectronicSignatureEventType{ + ElectronicSignatureEventTypeDocumentViewed, + ElectronicSignatureEventTypeConsentGiven, + ElectronicSignatureEventTypeFullNameTyped, + ElectronicSignatureEventTypeSignatureAccepted, + ElectronicSignatureEventTypeSignatureCompleted, + ElectronicSignatureEventTypeSealComputed, + ElectronicSignatureEventTypeTimestampRequested, + ElectronicSignatureEventTypeCertificateGenerated, + ElectronicSignatureEventTypeProcessingError, + } } -func (t *ElectronicSignatureEventType) UnmarshalText(data []byte) error { - val := string(data) - - switch val { - case ElectronicSignatureEventTypeDocumentViewed.String(): - *t = ElectronicSignatureEventTypeDocumentViewed - case ElectronicSignatureEventTypeConsentGiven.String(): - *t = ElectronicSignatureEventTypeConsentGiven - case ElectronicSignatureEventTypeFullNameTyped.String(): - *t = ElectronicSignatureEventTypeFullNameTyped - case ElectronicSignatureEventTypeSignatureAccepted.String(): - *t = ElectronicSignatureEventTypeSignatureAccepted - case ElectronicSignatureEventTypeSignatureCompleted.String(): - *t = ElectronicSignatureEventTypeSignatureCompleted - case ElectronicSignatureEventTypeSealComputed.String(): - *t = ElectronicSignatureEventTypeSealComputed - case ElectronicSignatureEventTypeTimestampRequested.String(): - *t = ElectronicSignatureEventTypeTimestampRequested - case ElectronicSignatureEventTypeCertificateGenerated.String(): - *t = ElectronicSignatureEventTypeCertificateGenerated - case ElectronicSignatureEventTypeProcessingError.String(): - *t = ElectronicSignatureEventTypeProcessingError - default: - return fmt.Errorf("invalid ElectronicSignatureEventType value: %q", val) +func (v ElectronicSignatureEventType) IsValid() bool { + switch v { + case + ElectronicSignatureEventTypeDocumentViewed, + ElectronicSignatureEventTypeConsentGiven, + ElectronicSignatureEventTypeFullNameTyped, + ElectronicSignatureEventTypeSignatureAccepted, + ElectronicSignatureEventTypeSignatureCompleted, + ElectronicSignatureEventTypeSealComputed, + ElectronicSignatureEventTypeTimestampRequested, + ElectronicSignatureEventTypeCertificateGenerated, + ElectronicSignatureEventTypeProcessingError: + return true } + return false +} + +func (v ElectronicSignatureEventType) String() string { + return string(v) +} + +func (v ElectronicSignatureEventType) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *ElectronicSignatureEventType) UnmarshalText(text []byte) error { + val := ElectronicSignatureEventType(text) + if !val.IsValid() { + return fmt.Errorf("invalid ElectronicSignatureEventType value: %q", string(text)) + } + + *v = val + return nil } - -func (t ElectronicSignatureEventType) String() string { - return string(t) -} - -func (t *ElectronicSignatureEventType) Scan(value any) error { - var s string - - switch v := value.(type) { - case string: - s = v - case []byte: - s = string(v) - default: - return fmt.Errorf("invalid scan source for ElectronicSignatureEventType, expected string or []byte got %T", value) - } - - return t.UnmarshalText([]byte(s)) -} - -func (t ElectronicSignatureEventType) Value() (driver.Value, error) { - return t.String(), nil -} diff --git a/pkg/coredata/electronic_signature_status.go b/pkg/coredata/electronic_signature_status.go index 28dadc118..2414fdf86 100644 --- a/pkg/coredata/electronic_signature_status.go +++ b/pkg/coredata/electronic_signature_status.go @@ -15,7 +15,7 @@ package coredata import ( - "database/sql/driver" + "encoding" "fmt" ) @@ -31,44 +31,51 @@ const ( ElectronicSignatureStatusFailed ElectronicSignatureStatus = "FAILED" ) -func (s ElectronicSignatureStatus) MarshalText() ([]byte, error) { - return []byte(s.String()), nil +var ( + _ fmt.Stringer = ElectronicSignatureStatus("") + _ encoding.TextMarshaler = ElectronicSignatureStatus("") + _ encoding.TextUnmarshaler = (*ElectronicSignatureStatus)(nil) +) + +func ElectronicSignatureStatuses() []ElectronicSignatureStatus { + return []ElectronicSignatureStatus{ + ElectronicSignatureStatusPending, + ElectronicSignatureStatusAccepted, + ElectronicSignatureStatusProcessing, + ElectronicSignatureStatusCompleted, + ElectronicSignatureStatusFailed, + } } -func (s *ElectronicSignatureStatus) UnmarshalText(data []byte) error { - val := string(data) - - switch val { - case ElectronicSignatureStatusPending.String(): - *s = ElectronicSignatureStatusPending - case ElectronicSignatureStatusAccepted.String(): - *s = ElectronicSignatureStatusAccepted - case ElectronicSignatureStatusProcessing.String(): - *s = ElectronicSignatureStatusProcessing - case ElectronicSignatureStatusCompleted.String(): - *s = ElectronicSignatureStatusCompleted - case ElectronicSignatureStatusFailed.String(): - *s = ElectronicSignatureStatusFailed - default: - return fmt.Errorf("invalid ElectronicSignatureStatus value: %q", val) +func (v ElectronicSignatureStatus) IsValid() bool { + switch v { + case + ElectronicSignatureStatusPending, + ElectronicSignatureStatusAccepted, + ElectronicSignatureStatusProcessing, + ElectronicSignatureStatusCompleted, + ElectronicSignatureStatusFailed: + return true } + return false +} + +func (v ElectronicSignatureStatus) String() string { + return string(v) +} + +func (v ElectronicSignatureStatus) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *ElectronicSignatureStatus) UnmarshalText(text []byte) error { + val := ElectronicSignatureStatus(text) + if !val.IsValid() { + return fmt.Errorf("invalid ElectronicSignatureStatus value: %q", string(text)) + } + + *v = val + return nil } - -func (s ElectronicSignatureStatus) String() string { - return string(s) -} - -func (s *ElectronicSignatureStatus) Scan(value any) error { - val, ok := value.(string) - if !ok { - return fmt.Errorf("invalid scan source for ElectronicSignatureStatus, expected string got %T", value) - } - - return s.UnmarshalText([]byte(val)) -} - -func (s ElectronicSignatureStatus) Value() (driver.Value, error) { - return s.String(), nil -} diff --git a/pkg/coredata/email_status.go b/pkg/coredata/email_status.go index df9a1af0a..d3526b1af 100644 --- a/pkg/coredata/email_status.go +++ b/pkg/coredata/email_status.go @@ -15,7 +15,7 @@ package coredata import ( - "database/sql/driver" + "encoding" "fmt" ) @@ -30,44 +30,49 @@ const ( EmailStatusFailed EmailStatus = "FAILED" ) -func (s EmailStatus) MarshalText() ([]byte, error) { - return []byte(s.String()), nil +var ( + _ fmt.Stringer = EmailStatus("") + _ encoding.TextMarshaler = EmailStatus("") + _ encoding.TextUnmarshaler = (*EmailStatus)(nil) +) + +func EmailStatuses() []EmailStatus { + return []EmailStatus{ + EmailStatusPending, + EmailStatusProcessing, + EmailStatusSent, + EmailStatusFailed, + } } -func (s *EmailStatus) UnmarshalText(data []byte) error { - val := string(data) - - switch val { - case EmailStatusPending.String(): - *s = EmailStatusPending - case EmailStatusProcessing.String(): - *s = EmailStatusProcessing - case EmailStatusSent.String(): - *s = EmailStatusSent - case EmailStatusFailed.String(): - *s = EmailStatusFailed - default: - return fmt.Errorf("invalid EmailStatus value: %q", val) +func (v EmailStatus) IsValid() bool { + switch v { + case + EmailStatusPending, + EmailStatusProcessing, + EmailStatusSent, + EmailStatusFailed: + return true } + return false +} + +func (v EmailStatus) String() string { + return string(v) +} + +func (v EmailStatus) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *EmailStatus) UnmarshalText(text []byte) error { + val := EmailStatus(text) + if !val.IsValid() { + return fmt.Errorf("invalid EmailStatus value: %q", string(text)) + } + + *v = val + return nil } - -func (s EmailStatus) String() string { - return string(s) -} - -func (s *EmailStatus) Scan(value any) error { - switch v := value.(type) { - case string: - return s.UnmarshalText([]byte(v)) - case []byte: - return s.UnmarshalText(v) - default: - return fmt.Errorf("invalid scan source for EmailStatus, expected string or []byte got %T", value) - } -} - -func (s EmailStatus) Value() (driver.Value, error) { - return s.String(), nil -} diff --git a/pkg/coredata/evidence_description_status.go b/pkg/coredata/evidence_description_status.go index e2fcfcf30..64c3d10a4 100644 --- a/pkg/coredata/evidence_description_status.go +++ b/pkg/coredata/evidence_description_status.go @@ -15,7 +15,7 @@ package coredata import ( - "database/sql/driver" + "encoding" "fmt" ) @@ -30,42 +30,49 @@ const ( EvidenceDescriptionStatusFailed EvidenceDescriptionStatus = "FAILED" ) -func (s EvidenceDescriptionStatus) MarshalText() ([]byte, error) { - return []byte(s.String()), nil +var ( + _ fmt.Stringer = EvidenceDescriptionStatus("") + _ encoding.TextMarshaler = EvidenceDescriptionStatus("") + _ encoding.TextUnmarshaler = (*EvidenceDescriptionStatus)(nil) +) + +func EvidenceDescriptionStatuses() []EvidenceDescriptionStatus { + return []EvidenceDescriptionStatus{ + EvidenceDescriptionStatusPending, + EvidenceDescriptionStatusProcessing, + EvidenceDescriptionStatusCompleted, + EvidenceDescriptionStatusFailed, + } } -func (s *EvidenceDescriptionStatus) UnmarshalText(data []byte) error { - val := string(data) - - switch val { - case EvidenceDescriptionStatusPending.String(): - *s = EvidenceDescriptionStatusPending - case EvidenceDescriptionStatusProcessing.String(): - *s = EvidenceDescriptionStatusProcessing - case EvidenceDescriptionStatusCompleted.String(): - *s = EvidenceDescriptionStatusCompleted - case EvidenceDescriptionStatusFailed.String(): - *s = EvidenceDescriptionStatusFailed - default: - return fmt.Errorf("invalid EvidenceDescriptionStatus value: %q", val) +func (v EvidenceDescriptionStatus) IsValid() bool { + switch v { + case + EvidenceDescriptionStatusPending, + EvidenceDescriptionStatusProcessing, + EvidenceDescriptionStatusCompleted, + EvidenceDescriptionStatusFailed: + return true } + return false +} + +func (v EvidenceDescriptionStatus) String() string { + return string(v) +} + +func (v EvidenceDescriptionStatus) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *EvidenceDescriptionStatus) UnmarshalText(text []byte) error { + val := EvidenceDescriptionStatus(text) + if !val.IsValid() { + return fmt.Errorf("invalid EvidenceDescriptionStatus value: %q", string(text)) + } + + *v = val + return nil } - -func (s EvidenceDescriptionStatus) String() string { - return string(s) -} - -func (s *EvidenceDescriptionStatus) Scan(value any) error { - val, ok := value.(string) - if !ok { - return fmt.Errorf("invalid scan source for EvidenceDescriptionStatus, expected string got %T", value) - } - - return s.UnmarshalText([]byte(val)) -} - -func (s EvidenceDescriptionStatus) Value() (driver.Value, error) { - return s.String(), nil -} diff --git a/pkg/coredata/evidence_order_field.go b/pkg/coredata/evidence_order_field.go index a47dd07d4..95d7057f5 100644 --- a/pkg/coredata/evidence_order_field.go +++ b/pkg/coredata/evidence_order_field.go @@ -14,6 +14,13 @@ package coredata +import ( + "encoding" + "fmt" + + "go.probo.inc/probo/pkg/page" +) + type ( EvidenceOrderField string ) @@ -22,19 +29,48 @@ const ( EvidenceOrderFieldCreatedAt EvidenceOrderField = "CREATED_AT" ) +var ( + _ page.OrderField = EvidenceOrderField("") + _ fmt.Stringer = EvidenceOrderField("") + _ encoding.TextMarshaler = EvidenceOrderField("") + _ encoding.TextUnmarshaler = (*EvidenceOrderField)(nil) +) + +func EvidenceOrderFields() []EvidenceOrderField { + return []EvidenceOrderField{ + EvidenceOrderFieldCreatedAt, + } +} + +func (v EvidenceOrderField) IsValid() bool { + switch v { + case + EvidenceOrderFieldCreatedAt: + return true + } + + return false +} + +func (v EvidenceOrderField) String() string { + return string(v) +} + +func (v EvidenceOrderField) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *EvidenceOrderField) UnmarshalText(text []byte) error { + val := EvidenceOrderField(text) + if !val.IsValid() { + return fmt.Errorf("invalid EvidenceOrderField value: %q", string(text)) + } + + *v = val + + return nil +} + func (p EvidenceOrderField) Column() string { return string(p) } - -func (p EvidenceOrderField) String() string { - return string(p) -} - -func (p EvidenceOrderField) MarshalText() ([]byte, error) { - return []byte(p.String()), nil -} - -func (p *EvidenceOrderField) UnmarshalText(text []byte) error { - *p = EvidenceOrderField(text) - return nil -} diff --git a/pkg/coredata/evidence_state.go b/pkg/coredata/evidence_state.go index 00949dffc..5f04196d9 100644 --- a/pkg/coredata/evidence_state.go +++ b/pkg/coredata/evidence_state.go @@ -15,7 +15,7 @@ package coredata import ( - "database/sql/driver" + "encoding" "fmt" ) @@ -28,36 +28,45 @@ const ( EvidenceStateFulfilled EvidenceState = "FULFILLED" ) -func (es EvidenceState) MarshalText() ([]byte, error) { - return []byte(es), nil +var ( + _ fmt.Stringer = EvidenceState("") + _ encoding.TextMarshaler = EvidenceState("") + _ encoding.TextUnmarshaler = (*EvidenceState)(nil) +) + +func EvidenceStates() []EvidenceState { + return []EvidenceState{ + EvidenceStateRequested, + EvidenceStateFulfilled, + } } -func (es *EvidenceState) UnmarshalText(data []byte) error { - val := EvidenceState(data) - - switch val { - case EvidenceStateRequested, EvidenceStateFulfilled: - *es = val - default: - return fmt.Errorf("invalid EvidenceState value: %q", val) +func (v EvidenceState) IsValid() bool { + switch v { + case + EvidenceStateRequested, + EvidenceStateFulfilled: + return true } + return false +} + +func (v EvidenceState) String() string { + return string(v) +} + +func (v EvidenceState) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *EvidenceState) UnmarshalText(text []byte) error { + val := EvidenceState(text) + if !val.IsValid() { + return fmt.Errorf("invalid EvidenceState value: %q", string(text)) + } + + *v = val + return nil } - -func (es EvidenceState) String() string { - return string(es) -} - -func (es *EvidenceState) Scan(value any) error { - val, ok := value.(string) - if !ok { - return fmt.Errorf("invalid scan source for EvidenceState, expected string got %T", value) - } - - return es.UnmarshalText([]byte(val)) -} - -func (es EvidenceState) Value() (driver.Value, error) { - return string(es), nil -} diff --git a/pkg/coredata/evidence_type.go b/pkg/coredata/evidence_type.go index 1e7ab716b..2256b2122 100644 --- a/pkg/coredata/evidence_type.go +++ b/pkg/coredata/evidence_type.go @@ -15,7 +15,7 @@ package coredata import ( - "database/sql/driver" + "encoding" "fmt" ) @@ -28,36 +28,45 @@ const ( EvidenceTypeLink EvidenceType = "LINK" ) -func (et EvidenceType) MarshalText() ([]byte, error) { - return []byte(et), nil +var ( + _ fmt.Stringer = EvidenceType("") + _ encoding.TextMarshaler = EvidenceType("") + _ encoding.TextUnmarshaler = (*EvidenceType)(nil) +) + +func EvidenceTypes() []EvidenceType { + return []EvidenceType{ + EvidenceTypeFile, + EvidenceTypeLink, + } } -func (et *EvidenceType) UnmarshalText(data []byte) error { - val := EvidenceType(data) - - switch val { - case EvidenceTypeFile, EvidenceTypeLink: - *et = val - default: - return fmt.Errorf("invalid EvidenceType value: %q", val) +func (v EvidenceType) IsValid() bool { + switch v { + case + EvidenceTypeFile, + EvidenceTypeLink: + return true } + return false +} + +func (v EvidenceType) String() string { + return string(v) +} + +func (v EvidenceType) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *EvidenceType) UnmarshalText(text []byte) error { + val := EvidenceType(text) + if !val.IsValid() { + return fmt.Errorf("invalid EvidenceType value: %q", string(text)) + } + + *v = val + return nil } - -func (et EvidenceType) String() string { - return string(et) -} - -func (et *EvidenceType) Scan(value any) error { - val, ok := value.(string) - if !ok { - return fmt.Errorf("invalid scan source for EvidenceType, expected string got %T", value) - } - - return et.UnmarshalText([]byte(val)) -} - -func (et EvidenceType) Value() (driver.Value, error) { - return string(et), nil -} diff --git a/pkg/coredata/expire_reason.go b/pkg/coredata/expire_reason.go index 4c17f599c..b4792bde2 100644 --- a/pkg/coredata/expire_reason.go +++ b/pkg/coredata/expire_reason.go @@ -14,6 +14,11 @@ package coredata +import ( + "encoding" + "fmt" +) + type ( ExpireReason string ) @@ -23,3 +28,48 @@ const ( ExpireReasonRevoked ExpireReason = "revoked" ExpireReasonClosed ExpireReason = "closed" ) + +var ( + _ fmt.Stringer = ExpireReason("") + _ encoding.TextMarshaler = ExpireReason("") + _ encoding.TextUnmarshaler = (*ExpireReason)(nil) +) + +func ExpireReasons() []ExpireReason { + return []ExpireReason{ + ExpireReasonIdleTimeout, + ExpireReasonRevoked, + ExpireReasonClosed, + } +} + +func (v ExpireReason) IsValid() bool { + switch v { + case + ExpireReasonIdleTimeout, + ExpireReasonRevoked, + ExpireReasonClosed: + return true + } + + return false +} + +func (v ExpireReason) String() string { + return string(v) +} + +func (v ExpireReason) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *ExpireReason) UnmarshalText(text []byte) error { + val := ExpireReason(text) + if !val.IsValid() { + return fmt.Errorf("invalid ExpireReason value: %q", string(text)) + } + + *v = val + + return nil +} diff --git a/pkg/coredata/export_job_status.go b/pkg/coredata/export_job_status.go index 601c48270..fe2b3ccee 100644 --- a/pkg/coredata/export_job_status.go +++ b/pkg/coredata/export_job_status.go @@ -15,7 +15,7 @@ package coredata import ( - "database/sql/driver" + "encoding" "fmt" ) @@ -30,38 +30,49 @@ const ( ExportJobStatusFailed ExportJobStatus = "FAILED" ) -func (ejs ExportJobStatus) String() string { - return string(ejs) +var ( + _ fmt.Stringer = ExportJobStatus("") + _ encoding.TextMarshaler = ExportJobStatus("") + _ encoding.TextUnmarshaler = (*ExportJobStatus)(nil) +) + +func ExportJobStatuses() []ExportJobStatus { + return []ExportJobStatus{ + ExportJobStatusPending, + ExportJobStatusProcessing, + ExportJobStatusCompleted, + ExportJobStatusFailed, + } } -func (ejs *ExportJobStatus) Scan(value any) error { - var s string - - switch v := value.(type) { - case string: - s = v - case []byte: - s = string(v) - default: - return fmt.Errorf("unsupported type for ExportJobStatus: %T", value) +func (v ExportJobStatus) IsValid() bool { + switch v { + case + ExportJobStatusPending, + ExportJobStatusProcessing, + ExportJobStatusCompleted, + ExportJobStatusFailed: + return true } - switch s { - case ExportJobStatusPending.String(): - *ejs = ExportJobStatusPending - case ExportJobStatusProcessing.String(): - *ejs = ExportJobStatusProcessing - case ExportJobStatusCompleted.String(): - *ejs = ExportJobStatusCompleted - case ExportJobStatusFailed.String(): - *ejs = ExportJobStatusFailed - default: - return fmt.Errorf("invalid ExportJobStatus value: %q", s) + return false +} + +func (v ExportJobStatus) String() string { + return string(v) +} + +func (v ExportJobStatus) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *ExportJobStatus) UnmarshalText(text []byte) error { + val := ExportJobStatus(text) + if !val.IsValid() { + return fmt.Errorf("invalid ExportJobStatus value: %q", string(text)) } + *v = val + return nil } - -func (ejs ExportJobStatus) Value() (driver.Value, error) { - return ejs.String(), nil -} diff --git a/pkg/coredata/export_job_type.go b/pkg/coredata/export_job_type.go index 6c40e691b..2d8a3ba66 100644 --- a/pkg/coredata/export_job_type.go +++ b/pkg/coredata/export_job_type.go @@ -15,7 +15,7 @@ package coredata import ( - "database/sql/driver" + "encoding" "fmt" ) @@ -28,34 +28,45 @@ const ( ExportJobTypeDocument ExportJobType = "DOCUMENT" ) -func (ejt ExportJobType) String() string { - return string(ejt) +var ( + _ fmt.Stringer = ExportJobType("") + _ encoding.TextMarshaler = ExportJobType("") + _ encoding.TextUnmarshaler = (*ExportJobType)(nil) +) + +func ExportJobTypes() []ExportJobType { + return []ExportJobType{ + ExportJobTypeFramework, + ExportJobTypeDocument, + } } -func (ejt *ExportJobType) Scan(value any) error { - var s string - - switch v := value.(type) { - case string: - s = v - case []byte: - s = string(v) - default: - return fmt.Errorf("unsupported type for ExportJobType: %T", value) +func (v ExportJobType) IsValid() bool { + switch v { + case + ExportJobTypeFramework, + ExportJobTypeDocument: + return true } - switch s { - case ExportJobTypeFramework.String(): - *ejt = ExportJobTypeFramework - case ExportJobTypeDocument.String(): - *ejt = ExportJobTypeDocument - default: - return fmt.Errorf("invalid ExportJobType value: %q", s) + return false +} + +func (v ExportJobType) String() string { + return string(v) +} + +func (v ExportJobType) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *ExportJobType) UnmarshalText(text []byte) error { + val := ExportJobType(text) + if !val.IsValid() { + return fmt.Errorf("invalid ExportJobType value: %q", string(text)) } + *v = val + return nil } - -func (ejt ExportJobType) Value() (driver.Value, error) { - return ejt.String(), nil -} diff --git a/pkg/coredata/file_visibility.go b/pkg/coredata/file_visibility.go index d31abad39..32effac9e 100644 --- a/pkg/coredata/file_visibility.go +++ b/pkg/coredata/file_visibility.go @@ -15,7 +15,7 @@ package coredata import ( - "database/sql/driver" + "encoding" "fmt" ) @@ -26,34 +26,45 @@ const ( FileVisibilityPublic FileVisibility = "PUBLIC" ) -func (fv FileVisibility) String() string { - return string(fv) +var ( + _ fmt.Stringer = FileVisibility("") + _ encoding.TextMarshaler = FileVisibility("") + _ encoding.TextUnmarshaler = (*FileVisibility)(nil) +) + +func FileVisibilities() []FileVisibility { + return []FileVisibility{ + FileVisibilityPrivate, + FileVisibilityPublic, + } } -func (fv *FileVisibility) Scan(value any) error { - var s string - - switch v := value.(type) { - case string: - s = v - case []byte: - s = string(v) - default: - return fmt.Errorf("unsupported type for FileVisibility: %T", value) +func (v FileVisibility) IsValid() bool { + switch v { + case + FileVisibilityPrivate, + FileVisibilityPublic: + return true } - switch s { - case "PRIVATE": - *fv = FileVisibilityPrivate - case "PUBLIC": - *fv = FileVisibilityPublic - default: - return fmt.Errorf("invalid FileVisibility value: %q", s) + return false +} + +func (v FileVisibility) String() string { + return string(v) +} + +func (v FileVisibility) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *FileVisibility) UnmarshalText(text []byte) error { + val := FileVisibility(text) + if !val.IsValid() { + return fmt.Errorf("invalid FileVisibility value: %q", string(text)) } + *v = val + return nil } - -func (fv FileVisibility) Value() (driver.Value, error) { - return fv.String(), nil -} diff --git a/pkg/coredata/finding_kind.go b/pkg/coredata/finding_kind.go index 43118f5c2..ab2cc68a7 100644 --- a/pkg/coredata/finding_kind.go +++ b/pkg/coredata/finding_kind.go @@ -15,7 +15,7 @@ package coredata import ( - "database/sql/driver" + "encoding" "fmt" ) @@ -28,6 +28,12 @@ const ( FindingKindException FindingKind = "EXCEPTION" ) +var ( + _ fmt.Stringer = FindingKind("") + _ encoding.TextMarshaler = FindingKind("") + _ encoding.TextUnmarshaler = (*FindingKind)(nil) +) + func FindingKinds() []FindingKind { return []FindingKind{ FindingKindMinorNonconformity, @@ -37,38 +43,34 @@ func FindingKinds() []FindingKind { } } -func (fk FindingKind) String() string { - return string(fk) +func (v FindingKind) IsValid() bool { + switch v { + case + FindingKindMinorNonconformity, + FindingKindMajorNonconformity, + FindingKindObservation, + FindingKindException: + return true + } + + return false } -func (fk *FindingKind) Scan(value any) error { - var s string +func (v FindingKind) String() string { + return string(v) +} - switch v := value.(type) { - case string: - s = v - case []byte: - s = string(v) - default: - return fmt.Errorf("unsupported type for FindingKind: %T", value) +func (v FindingKind) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *FindingKind) UnmarshalText(text []byte) error { + val := FindingKind(text) + if !val.IsValid() { + return fmt.Errorf("invalid FindingKind value: %q", string(text)) } - switch s { - case "MINOR_NONCONFORMITY": - *fk = FindingKindMinorNonconformity - case "MAJOR_NONCONFORMITY": - *fk = FindingKindMajorNonconformity - case "OBSERVATION": - *fk = FindingKindObservation - case "EXCEPTION": - *fk = FindingKindException - default: - return fmt.Errorf("invalid FindingKind value: %q", s) - } + *v = val return nil } - -func (fk FindingKind) Value() (driver.Value, error) { - return fk.String(), nil -} diff --git a/pkg/coredata/finding_order_field.go b/pkg/coredata/finding_order_field.go index 38f40ab14..e4bca2f5c 100644 --- a/pkg/coredata/finding_order_field.go +++ b/pkg/coredata/finding_order_field.go @@ -15,7 +15,10 @@ package coredata import ( + "encoding" "fmt" + + "go.probo.inc/probo/pkg/page" ) type FindingOrderField string @@ -30,31 +33,60 @@ const ( FindingOrderFieldKind FindingOrderField = "KIND" ) +var ( + _ page.OrderField = FindingOrderField("") + _ fmt.Stringer = FindingOrderField("") + _ encoding.TextMarshaler = FindingOrderField("") + _ encoding.TextUnmarshaler = (*FindingOrderField)(nil) +) + +func FindingOrderFields() []FindingOrderField { + return []FindingOrderField{ + FindingOrderFieldCreatedAt, + FindingOrderFieldIdentifiedOn, + FindingOrderFieldDueDate, + FindingOrderFieldStatus, + FindingOrderFieldPriority, + FindingOrderFieldReferenceId, + FindingOrderFieldKind, + } +} + +func (v FindingOrderField) IsValid() bool { + switch v { + case + FindingOrderFieldCreatedAt, + FindingOrderFieldIdentifiedOn, + FindingOrderFieldDueDate, + FindingOrderFieldStatus, + FindingOrderFieldPriority, + FindingOrderFieldReferenceId, + FindingOrderFieldKind: + return true + } + + return false +} + +func (v FindingOrderField) String() string { + return string(v) +} + +func (v FindingOrderField) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *FindingOrderField) UnmarshalText(text []byte) error { + val := FindingOrderField(text) + if !val.IsValid() { + return fmt.Errorf("invalid FindingOrderField value: %q", string(text)) + } + + *v = val + + return nil +} + func (p FindingOrderField) Column() string { return string(p) } - -func (p FindingOrderField) String() string { - return string(p) -} - -func (p FindingOrderField) MarshalText() ([]byte, error) { - return []byte(p.String()), nil -} - -func (p *FindingOrderField) UnmarshalText(text []byte) error { - val := string(text) - switch val { - case string(FindingOrderFieldCreatedAt), - string(FindingOrderFieldIdentifiedOn), - string(FindingOrderFieldDueDate), - string(FindingOrderFieldStatus), - string(FindingOrderFieldPriority), - string(FindingOrderFieldReferenceId), - string(FindingOrderFieldKind): - *p = FindingOrderField(val) - return nil - } - - return fmt.Errorf("invalid FindingOrderField value: %q", val) -} diff --git a/pkg/coredata/finding_priority.go b/pkg/coredata/finding_priority.go index 21cae456f..f80e561b2 100644 --- a/pkg/coredata/finding_priority.go +++ b/pkg/coredata/finding_priority.go @@ -15,7 +15,7 @@ package coredata import ( - "database/sql/driver" + "encoding" "fmt" ) @@ -27,6 +27,12 @@ const ( FindingPriorityHigh FindingPriority = "HIGH" ) +var ( + _ fmt.Stringer = FindingPriority("") + _ encoding.TextMarshaler = FindingPriority("") + _ encoding.TextUnmarshaler = (*FindingPriority)(nil) +) + func FindingPriorities() []FindingPriority { return []FindingPriority{ FindingPriorityLow, @@ -35,36 +41,33 @@ func FindingPriorities() []FindingPriority { } } -func (fp FindingPriority) String() string { - return string(fp) +func (v FindingPriority) IsValid() bool { + switch v { + case + FindingPriorityLow, + FindingPriorityMedium, + FindingPriorityHigh: + return true + } + + return false } -func (fp *FindingPriority) Scan(value any) error { - var s string +func (v FindingPriority) String() string { + return string(v) +} - switch v := value.(type) { - case string: - s = v - case []byte: - s = string(v) - default: - return fmt.Errorf("unsupported type for FindingPriority: %T", value) +func (v FindingPriority) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *FindingPriority) UnmarshalText(text []byte) error { + val := FindingPriority(text) + if !val.IsValid() { + return fmt.Errorf("invalid FindingPriority value: %q", string(text)) } - switch s { - case "LOW": - *fp = FindingPriorityLow - case "MEDIUM": - *fp = FindingPriorityMedium - case "HIGH": - *fp = FindingPriorityHigh - default: - return fmt.Errorf("invalid FindingPriority value: %q", s) - } + *v = val return nil } - -func (fp FindingPriority) Value() (driver.Value, error) { - return fp.String(), nil -} diff --git a/pkg/coredata/finding_status.go b/pkg/coredata/finding_status.go index b47efc373..d7d260f01 100644 --- a/pkg/coredata/finding_status.go +++ b/pkg/coredata/finding_status.go @@ -15,7 +15,7 @@ package coredata import ( - "database/sql/driver" + "encoding" "fmt" ) @@ -30,6 +30,12 @@ const ( FindingStatusFalsePositive FindingStatus = "FALSE_POSITIVE" ) +var ( + _ fmt.Stringer = FindingStatus("") + _ encoding.TextMarshaler = FindingStatus("") + _ encoding.TextUnmarshaler = (*FindingStatus)(nil) +) + func FindingStatuses() []FindingStatus { return []FindingStatus{ FindingStatusOpen, @@ -41,42 +47,36 @@ func FindingStatuses() []FindingStatus { } } -func (fs FindingStatus) String() string { - return string(fs) +func (v FindingStatus) IsValid() bool { + switch v { + case + FindingStatusOpen, + FindingStatusInProgress, + FindingStatusClosed, + FindingStatusRiskAccepted, + FindingStatusMitigated, + FindingStatusFalsePositive: + return true + } + + return false } -func (fs *FindingStatus) Scan(value any) error { - var s string +func (v FindingStatus) String() string { + return string(v) +} - switch v := value.(type) { - case string: - s = v - case []byte: - s = string(v) - default: - return fmt.Errorf("unsupported type for FindingStatus: %T", value) +func (v FindingStatus) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *FindingStatus) UnmarshalText(text []byte) error { + val := FindingStatus(text) + if !val.IsValid() { + return fmt.Errorf("invalid FindingStatus value: %q", string(text)) } - switch s { - case "OPEN": - *fs = FindingStatusOpen - case "IN_PROGRESS": - *fs = FindingStatusInProgress - case "CLOSED": - *fs = FindingStatusClosed - case "RISK_ACCEPTED": - *fs = FindingStatusRiskAccepted - case "MITIGATED": - *fs = FindingStatusMitigated - case "FALSE_POSITIVE": - *fs = FindingStatusFalsePositive - default: - return fmt.Errorf("invalid FindingStatus value: %q", s) - } + *v = val return nil } - -func (fs FindingStatus) Value() (driver.Value, error) { - return fs.String(), nil -} diff --git a/pkg/coredata/framework_order_field.go b/pkg/coredata/framework_order_field.go index a5b44b64a..21d715e29 100644 --- a/pkg/coredata/framework_order_field.go +++ b/pkg/coredata/framework_order_field.go @@ -14,6 +14,13 @@ package coredata +import ( + "encoding" + "fmt" + + "go.probo.inc/probo/pkg/page" +) + type ( FrameworkOrderField string ) @@ -22,19 +29,48 @@ const ( FrameworkOrderFieldCreatedAt FrameworkOrderField = "CREATED_AT" ) +var ( + _ page.OrderField = FrameworkOrderField("") + _ fmt.Stringer = FrameworkOrderField("") + _ encoding.TextMarshaler = FrameworkOrderField("") + _ encoding.TextUnmarshaler = (*FrameworkOrderField)(nil) +) + +func FrameworkOrderFields() []FrameworkOrderField { + return []FrameworkOrderField{ + FrameworkOrderFieldCreatedAt, + } +} + +func (v FrameworkOrderField) IsValid() bool { + switch v { + case + FrameworkOrderFieldCreatedAt: + return true + } + + return false +} + +func (v FrameworkOrderField) String() string { + return string(v) +} + +func (v FrameworkOrderField) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *FrameworkOrderField) UnmarshalText(text []byte) error { + val := FrameworkOrderField(text) + if !val.IsValid() { + return fmt.Errorf("invalid FrameworkOrderField value: %q", string(text)) + } + + *v = val + + return nil +} + func (p FrameworkOrderField) Column() string { return string(p) } - -func (p FrameworkOrderField) String() string { - return string(p) -} - -func (p FrameworkOrderField) MarshalText() ([]byte, error) { - return []byte(p.String()), nil -} - -func (p *FrameworkOrderField) UnmarshalText(text []byte) error { - *p = FrameworkOrderField(text) - return nil -} diff --git a/pkg/coredata/identity_order_field.go b/pkg/coredata/identity_order_field.go index d797800ce..c1c9dd954 100644 --- a/pkg/coredata/identity_order_field.go +++ b/pkg/coredata/identity_order_field.go @@ -14,6 +14,13 @@ package coredata +import ( + "encoding" + "fmt" + + "go.probo.inc/probo/pkg/page" +) + type ( IdentityOrderField string ) @@ -22,19 +29,48 @@ const ( IdentityOrderFieldCreatedAt IdentityOrderField = "CREATED_AT" ) +var ( + _ page.OrderField = IdentityOrderField("") + _ fmt.Stringer = IdentityOrderField("") + _ encoding.TextMarshaler = IdentityOrderField("") + _ encoding.TextUnmarshaler = (*IdentityOrderField)(nil) +) + +func IdentityOrderFields() []IdentityOrderField { + return []IdentityOrderField{ + IdentityOrderFieldCreatedAt, + } +} + +func (v IdentityOrderField) IsValid() bool { + switch v { + case + IdentityOrderFieldCreatedAt: + return true + } + + return false +} + +func (v IdentityOrderField) String() string { + return string(v) +} + +func (v IdentityOrderField) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *IdentityOrderField) UnmarshalText(text []byte) error { + val := IdentityOrderField(text) + if !val.IsValid() { + return fmt.Errorf("invalid IdentityOrderField value: %q", string(text)) + } + + *v = val + + return nil +} + func (p IdentityOrderField) Column() string { return string(p) } - -func (p IdentityOrderField) String() string { - return string(p) -} - -func (p IdentityOrderField) MarshalText() ([]byte, error) { - return []byte(p.String()), nil -} - -func (p *IdentityOrderField) UnmarshalText(text []byte) error { - *p = IdentityOrderField(text) - return nil -} diff --git a/pkg/coredata/invitation_order_field.go b/pkg/coredata/invitation_order_field.go index 15cefe4a8..79d4a7a37 100644 --- a/pkg/coredata/invitation_order_field.go +++ b/pkg/coredata/invitation_order_field.go @@ -14,7 +14,12 @@ package coredata -import "fmt" +import ( + "encoding" + "fmt" + + "go.probo.inc/probo/pkg/page" +) // InvitationOrderField defines the fields that can be used to order invitations type InvitationOrderField string @@ -24,6 +29,48 @@ const ( InvitationOrderFieldCreatedAt InvitationOrderField = "CREATED_AT" ) +var ( + _ page.OrderField = InvitationOrderField("") + _ fmt.Stringer = InvitationOrderField("") + _ encoding.TextMarshaler = InvitationOrderField("") + _ encoding.TextUnmarshaler = (*InvitationOrderField)(nil) +) + +func InvitationOrderFields() []InvitationOrderField { + return []InvitationOrderField{ + InvitationOrderFieldCreatedAt, + } +} + +func (v InvitationOrderField) IsValid() bool { + switch v { + case + InvitationOrderFieldCreatedAt: + return true + } + + return false +} + +func (v InvitationOrderField) String() string { + return string(v) +} + +func (v InvitationOrderField) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *InvitationOrderField) UnmarshalText(text []byte) error { + val := InvitationOrderField(text) + if !val.IsValid() { + return fmt.Errorf("invalid InvitationOrderField value: %q", string(text)) + } + + *v = val + + return nil +} + func (p InvitationOrderField) Column() string { switch p { case InvitationOrderFieldCreatedAt: @@ -32,29 +79,3 @@ func (p InvitationOrderField) Column() string { panic(fmt.Sprintf("unsupported order by: %s", p)) } - -func (e InvitationOrderField) IsValid() bool { - switch e { - case InvitationOrderFieldCreatedAt: - return true - } - - return false -} - -func (e InvitationOrderField) String() string { - return string(e) -} - -func (e *InvitationOrderField) UnmarshalText(text []byte) error { - *e = InvitationOrderField(text) - if !e.IsValid() { - return fmt.Errorf("%s is not a valid InvitationOrderField", string(text)) - } - - return nil -} - -func (e InvitationOrderField) MarshalText() ([]byte, error) { - return []byte(e.String()), nil -} diff --git a/pkg/coredata/invitation_status.go b/pkg/coredata/invitation_status.go index 8a2f61d00..f15f5fb18 100644 --- a/pkg/coredata/invitation_status.go +++ b/pkg/coredata/invitation_status.go @@ -16,6 +16,7 @@ package coredata import ( "database/sql/driver" + "encoding" "fmt" "strings" ) @@ -31,40 +32,43 @@ const ( InvitationStatusExpired InvitationStatus = "EXPIRED" ) -func (tcv InvitationStatus) String() string { - return string(tcv) +var ( + _ fmt.Stringer = InvitationStatus("") + _ encoding.TextMarshaler = InvitationStatus("") + _ encoding.TextUnmarshaler = (*InvitationStatus)(nil) +) + +func (v InvitationStatus) IsValid() bool { + switch v { + case + InvitationStatusPending, + InvitationStatusAccepted, + InvitationStatusExpired: + return true + } + + return false } -func (tcv *InvitationStatus) Scan(value any) error { - var s string +func (v InvitationStatus) String() string { + return string(v) +} - switch v := value.(type) { - case string: - s = v - case []byte: - s = string(v) - default: - return fmt.Errorf("unsupported type for TrustCenterVisibility: %T", value) +func (v InvitationStatus) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *InvitationStatus) UnmarshalText(text []byte) error { + val := InvitationStatus(text) + if !val.IsValid() { + return fmt.Errorf("invalid InvitationStatus value: %q", string(text)) } - switch s { - case "PENDING": - *tcv = InvitationStatusPending - case "ACCEPTED": - *tcv = InvitationStatusAccepted - case "EXPIRED": - *tcv = InvitationStatusExpired - default: - return fmt.Errorf("invalid InvitationStatus value: %q", s) - } + *v = val return nil } -func (tcv InvitationStatus) Value() (driver.Value, error) { - return tcv.String(), nil -} - func (statuses InvitationStatuses) Value() (driver.Value, error) { if len(statuses) == 0 { return nil, nil diff --git a/pkg/coredata/mailing_list_subscriber_order_field.go b/pkg/coredata/mailing_list_subscriber_order_field.go index bcf8b6956..c04e3bf8f 100644 --- a/pkg/coredata/mailing_list_subscriber_order_field.go +++ b/pkg/coredata/mailing_list_subscriber_order_field.go @@ -14,7 +14,12 @@ package coredata -import "fmt" +import ( + "encoding" + "fmt" + + "go.probo.inc/probo/pkg/page" +) type MailingListSubscriberOrderField string @@ -22,8 +27,46 @@ const ( MailingListSubscriberOrderFieldCreatedAt MailingListSubscriberOrderField = "CREATED_AT" ) -func (f MailingListSubscriberOrderField) String() string { - return string(f) +var ( + _ page.OrderField = MailingListSubscriberOrderField("") + _ fmt.Stringer = MailingListSubscriberOrderField("") + _ encoding.TextMarshaler = MailingListSubscriberOrderField("") + _ encoding.TextUnmarshaler = (*MailingListSubscriberOrderField)(nil) +) + +func MailingListSubscriberOrderFields() []MailingListSubscriberOrderField { + return []MailingListSubscriberOrderField{ + MailingListSubscriberOrderFieldCreatedAt, + } +} + +func (v MailingListSubscriberOrderField) IsValid() bool { + switch v { + case + MailingListSubscriberOrderFieldCreatedAt: + return true + } + + return false +} + +func (v MailingListSubscriberOrderField) String() string { + return string(v) +} + +func (v MailingListSubscriberOrderField) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *MailingListSubscriberOrderField) UnmarshalText(text []byte) error { + val := MailingListSubscriberOrderField(text) + if !val.IsValid() { + return fmt.Errorf("invalid MailingListSubscriberOrderField value: %q", string(text)) + } + + *v = val + + return nil } func (f MailingListSubscriberOrderField) Column() string { diff --git a/pkg/coredata/mailing_list_subscriber_status.go b/pkg/coredata/mailing_list_subscriber_status.go index 928e6bdae..7a4cd0a91 100644 --- a/pkg/coredata/mailing_list_subscriber_status.go +++ b/pkg/coredata/mailing_list_subscriber_status.go @@ -15,7 +15,7 @@ package coredata import ( - "database/sql/driver" + "encoding" "fmt" ) @@ -26,34 +26,45 @@ const ( MailingListSubscriberStatusConfirmed MailingListSubscriberStatus = "CONFIRMED" ) -func (s MailingListSubscriberStatus) String() string { - return string(s) +var ( + _ fmt.Stringer = MailingListSubscriberStatus("") + _ encoding.TextMarshaler = MailingListSubscriberStatus("") + _ encoding.TextUnmarshaler = (*MailingListSubscriberStatus)(nil) +) + +func MailingListSubscriberStatuses() []MailingListSubscriberStatus { + return []MailingListSubscriberStatus{ + MailingListSubscriberStatusPending, + MailingListSubscriberStatusConfirmed, + } } -func (s *MailingListSubscriberStatus) Scan(value any) error { - var str string - - switch v := value.(type) { - case string: - str = v - case []byte: - str = string(v) - default: - return fmt.Errorf("unsupported type for MailingListSubscriberStatus: %T", value) +func (v MailingListSubscriberStatus) IsValid() bool { + switch v { + case + MailingListSubscriberStatusPending, + MailingListSubscriberStatusConfirmed: + return true } - switch str { - case "PENDING": - *s = MailingListSubscriberStatusPending - case "CONFIRMED": - *s = MailingListSubscriberStatusConfirmed - default: - return fmt.Errorf("invalid MailingListSubscriberStatus value: %q", str) + return false +} + +func (v MailingListSubscriberStatus) String() string { + return string(v) +} + +func (v MailingListSubscriberStatus) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *MailingListSubscriberStatus) UnmarshalText(text []byte) error { + val := MailingListSubscriberStatus(text) + if !val.IsValid() { + return fmt.Errorf("invalid MailingListSubscriberStatus value: %q", string(text)) } + *v = val + return nil } - -func (s MailingListSubscriberStatus) Value() (driver.Value, error) { - return s.String(), nil -} diff --git a/pkg/coredata/mailing_list_update_order_field.go b/pkg/coredata/mailing_list_update_order_field.go index b259935aa..1cf6e6fd9 100644 --- a/pkg/coredata/mailing_list_update_order_field.go +++ b/pkg/coredata/mailing_list_update_order_field.go @@ -14,7 +14,12 @@ package coredata -import "fmt" +import ( + "encoding" + "fmt" + + "go.probo.inc/probo/pkg/page" +) type MailingListUpdateOrderField string @@ -23,8 +28,48 @@ const ( MailingListUpdateOrderFieldUpdatedAt MailingListUpdateOrderField = "UPDATED_AT" ) -func (f MailingListUpdateOrderField) String() string { - return string(f) +var ( + _ page.OrderField = MailingListUpdateOrderField("") + _ fmt.Stringer = MailingListUpdateOrderField("") + _ encoding.TextMarshaler = MailingListUpdateOrderField("") + _ encoding.TextUnmarshaler = (*MailingListUpdateOrderField)(nil) +) + +func MailingListUpdateOrderFields() []MailingListUpdateOrderField { + return []MailingListUpdateOrderField{ + MailingListUpdateOrderFieldCreatedAt, + MailingListUpdateOrderFieldUpdatedAt, + } +} + +func (v MailingListUpdateOrderField) IsValid() bool { + switch v { + case + MailingListUpdateOrderFieldCreatedAt, + MailingListUpdateOrderFieldUpdatedAt: + return true + } + + return false +} + +func (v MailingListUpdateOrderField) String() string { + return string(v) +} + +func (v MailingListUpdateOrderField) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *MailingListUpdateOrderField) UnmarshalText(text []byte) error { + val := MailingListUpdateOrderField(text) + if !val.IsValid() { + return fmt.Errorf("invalid MailingListUpdateOrderField value: %q", string(text)) + } + + *v = val + + return nil } func (f MailingListUpdateOrderField) Column() string { diff --git a/pkg/coredata/mailing_list_update_status.go b/pkg/coredata/mailing_list_update_status.go index 90799e311..c7e0f4be0 100644 --- a/pkg/coredata/mailing_list_update_status.go +++ b/pkg/coredata/mailing_list_update_status.go @@ -15,7 +15,7 @@ package coredata import ( - "database/sql/driver" + "encoding" "fmt" ) @@ -28,38 +28,49 @@ const ( MailingListUpdateStatusSent MailingListUpdateStatus = "SENT" ) -func (s MailingListUpdateStatus) String() string { - return string(s) +var ( + _ fmt.Stringer = MailingListUpdateStatus("") + _ encoding.TextMarshaler = MailingListUpdateStatus("") + _ encoding.TextUnmarshaler = (*MailingListUpdateStatus)(nil) +) + +func MailingListUpdateStatuses() []MailingListUpdateStatus { + return []MailingListUpdateStatus{ + MailingListUpdateStatusDraft, + MailingListUpdateStatusEnqueued, + MailingListUpdateStatusProcessing, + MailingListUpdateStatusSent, + } } -func (s *MailingListUpdateStatus) Scan(value any) error { - var str string - - switch v := value.(type) { - case string: - str = v - case []byte: - str = string(v) - default: - return fmt.Errorf("unsupported type for MailingListUpdateStatus: %T", value) +func (v MailingListUpdateStatus) IsValid() bool { + switch v { + case + MailingListUpdateStatusDraft, + MailingListUpdateStatusEnqueued, + MailingListUpdateStatusProcessing, + MailingListUpdateStatusSent: + return true } - switch str { - case "DRAFT": - *s = MailingListUpdateStatusDraft - case "ENQUEUED": - *s = MailingListUpdateStatusEnqueued - case "PROCESSING": - *s = MailingListUpdateStatusProcessing - case "SENT": - *s = MailingListUpdateStatusSent - default: - return fmt.Errorf("invalid MailingListUpdateStatus value: %q", str) + return false +} + +func (v MailingListUpdateStatus) String() string { + return string(v) +} + +func (v MailingListUpdateStatus) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *MailingListUpdateStatus) UnmarshalText(text []byte) error { + val := MailingListUpdateStatus(text) + if !val.IsValid() { + return fmt.Errorf("invalid MailingListUpdateStatus value: %q", string(text)) } + *v = val + return nil } - -func (s MailingListUpdateStatus) Value() (driver.Value, error) { - return s.String(), nil -} diff --git a/pkg/coredata/member_role.go b/pkg/coredata/member_role.go index fab1439d3..da4c8a5d0 100644 --- a/pkg/coredata/member_role.go +++ b/pkg/coredata/member_role.go @@ -15,7 +15,7 @@ package coredata import ( - "database/sql/driver" + "encoding" "fmt" ) @@ -29,40 +29,51 @@ const ( MembershipRoleAuditor MembershipRole = "AUDITOR" ) -func (r MembershipRole) String() string { - return string(r) +var ( + _ fmt.Stringer = MembershipRole("") + _ encoding.TextMarshaler = MembershipRole("") + _ encoding.TextUnmarshaler = (*MembershipRole)(nil) +) + +func MembershipRoles() []MembershipRole { + return []MembershipRole{ + MembershipRoleOwner, + MembershipRoleAdmin, + MembershipRoleEmployee, + MembershipRoleViewer, + MembershipRoleAuditor, + } } -func (r *MembershipRole) Scan(value any) error { - var s string - - switch v := value.(type) { - case string: - s = v - case []byte: - s = string(v) - default: - return fmt.Errorf("unsupported type for MembershipRole: %T", value) +func (v MembershipRole) IsValid() bool { + switch v { + case + MembershipRoleOwner, + MembershipRoleAdmin, + MembershipRoleEmployee, + MembershipRoleViewer, + MembershipRoleAuditor: + return true } - switch s { - case "OWNER": - *r = MembershipRoleOwner - case "ADMIN": - *r = MembershipRoleAdmin - case "EMPLOYEE": - *r = MembershipRoleEmployee - case "VIEWER": - *r = MembershipRoleViewer - case "AUDITOR": - *r = MembershipRoleAuditor - default: - return fmt.Errorf("invalid MembershipRole value: %q", s) + return false +} + +func (v MembershipRole) String() string { + return string(v) +} + +func (v MembershipRole) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *MembershipRole) UnmarshalText(text []byte) error { + val := MembershipRole(text) + if !val.IsValid() { + return fmt.Errorf("invalid MembershipRole value: %q", string(text)) } + *v = val + return nil } - -func (r MembershipRole) Value() (driver.Value, error) { - return r.String(), nil -} diff --git a/pkg/coredata/membership_order_field.go b/pkg/coredata/membership_order_field.go index c2220cdc5..ed6df87e2 100644 --- a/pkg/coredata/membership_order_field.go +++ b/pkg/coredata/membership_order_field.go @@ -14,6 +14,13 @@ package coredata +import ( + "encoding" + "fmt" + + "go.probo.inc/probo/pkg/page" +) + type ( MembershipOrderField string ) @@ -26,6 +33,56 @@ const ( MembershipOrderFieldCreatedAt MembershipOrderField = "CREATED_AT" ) +var ( + _ page.OrderField = MembershipOrderField("") + _ fmt.Stringer = MembershipOrderField("") + _ encoding.TextMarshaler = MembershipOrderField("") + _ encoding.TextUnmarshaler = (*MembershipOrderField)(nil) +) + +func MembershipOrderFields() []MembershipOrderField { + return []MembershipOrderField{ + MembershipOrderFieldOrganizationName, + MembershipOrderFieldFullName, + MembershipOrderFieldEmailAddress, + MembershipOrderFieldRole, + MembershipOrderFieldCreatedAt, + } +} + +func (v MembershipOrderField) IsValid() bool { + switch v { + case + MembershipOrderFieldOrganizationName, + MembershipOrderFieldFullName, + MembershipOrderFieldEmailAddress, + MembershipOrderFieldRole, + MembershipOrderFieldCreatedAt: + return true + } + + return false +} + +func (v MembershipOrderField) String() string { + return string(v) +} + +func (v MembershipOrderField) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *MembershipOrderField) UnmarshalText(text []byte) error { + val := MembershipOrderField(text) + if !val.IsValid() { + return fmt.Errorf("invalid MembershipOrderField value: %q", string(text)) + } + + *v = val + + return nil +} + func (p MembershipOrderField) Column() string { switch p { case MembershipOrderFieldOrganizationName: @@ -42,16 +99,3 @@ func (p MembershipOrderField) Column() string { return string(p) } - -func (p MembershipOrderField) String() string { - return string(p) -} - -func (p MembershipOrderField) MarshalText() ([]byte, error) { - return []byte(p.String()), nil -} - -func (p *MembershipOrderField) UnmarshalText(text []byte) error { - *p = MembershipOrderField(text) - return nil -} diff --git a/pkg/coredata/membership_profile_order_field.go b/pkg/coredata/membership_profile_order_field.go index 3e6f59051..2f11f48f2 100644 --- a/pkg/coredata/membership_profile_order_field.go +++ b/pkg/coredata/membership_profile_order_field.go @@ -14,6 +14,13 @@ package coredata +import ( + "encoding" + "fmt" + + "go.probo.inc/probo/pkg/page" +) + type ( MembershipProfileOrderField string ) @@ -26,19 +33,56 @@ const ( MembershipProfileOrderFieldState MembershipProfileOrderField = "STATE" ) +var ( + _ page.OrderField = MembershipProfileOrderField("") + _ fmt.Stringer = MembershipProfileOrderField("") + _ encoding.TextMarshaler = MembershipProfileOrderField("") + _ encoding.TextUnmarshaler = (*MembershipProfileOrderField)(nil) +) + +func MembershipProfileOrderFields() []MembershipProfileOrderField { + return []MembershipProfileOrderField{ + MembershipProfileOrderFieldCreatedAt, + MembershipProfileOrderFieldFullName, + MembershipProfileOrderFieldKind, + MembershipProfileOrderFieldOrganizationName, + MembershipProfileOrderFieldState, + } +} + +func (v MembershipProfileOrderField) IsValid() bool { + switch v { + case + MembershipProfileOrderFieldCreatedAt, + MembershipProfileOrderFieldFullName, + MembershipProfileOrderFieldKind, + MembershipProfileOrderFieldOrganizationName, + MembershipProfileOrderFieldState: + return true + } + + return false +} + +func (v MembershipProfileOrderField) String() string { + return string(v) +} + +func (v MembershipProfileOrderField) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *MembershipProfileOrderField) UnmarshalText(text []byte) error { + val := MembershipProfileOrderField(text) + if !val.IsValid() { + return fmt.Errorf("invalid MembershipProfileOrderField value: %q", string(text)) + } + + *v = val + + return nil +} + func (p MembershipProfileOrderField) Column() string { return string(p) } - -func (p MembershipProfileOrderField) String() string { - return string(p) -} - -func (p MembershipProfileOrderField) MarshalText() ([]byte, error) { - return []byte(p.String()), nil -} - -func (p *MembershipProfileOrderField) UnmarshalText(text []byte) error { - *p = MembershipProfileOrderField(text) - return nil -} diff --git a/pkg/coredata/mesure_order_field.go b/pkg/coredata/mesure_order_field.go index 2ba661e59..3cd413c91 100644 --- a/pkg/coredata/mesure_order_field.go +++ b/pkg/coredata/mesure_order_field.go @@ -14,6 +14,13 @@ package coredata +import ( + "encoding" + "fmt" + + "go.probo.inc/probo/pkg/page" +) + type ( MeasureOrderField string ) @@ -23,19 +30,50 @@ const ( MeasureOrderFieldName MeasureOrderField = "NAME" ) +var ( + _ page.OrderField = MeasureOrderField("") + _ fmt.Stringer = MeasureOrderField("") + _ encoding.TextMarshaler = MeasureOrderField("") + _ encoding.TextUnmarshaler = (*MeasureOrderField)(nil) +) + +func MeasureOrderFields() []MeasureOrderField { + return []MeasureOrderField{ + MeasureOrderFieldCreatedAt, + MeasureOrderFieldName, + } +} + +func (v MeasureOrderField) IsValid() bool { + switch v { + case + MeasureOrderFieldCreatedAt, + MeasureOrderFieldName: + return true + } + + return false +} + +func (v MeasureOrderField) String() string { + return string(v) +} + +func (v MeasureOrderField) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *MeasureOrderField) UnmarshalText(text []byte) error { + val := MeasureOrderField(text) + if !val.IsValid() { + return fmt.Errorf("invalid MeasureOrderField value: %q", string(text)) + } + + *v = val + + return nil +} + func (p MeasureOrderField) Column() string { return string(p) } - -func (p MeasureOrderField) String() string { - return string(p) -} - -func (p MeasureOrderField) MarshalText() ([]byte, error) { - return []byte(p.String()), nil -} - -func (p *MeasureOrderField) UnmarshalText(text []byte) error { - *p = MeasureOrderField(text) - return nil -} diff --git a/pkg/coredata/mesure_state.go b/pkg/coredata/mesure_state.go index cb4db3453..0751e336b 100644 --- a/pkg/coredata/mesure_state.go +++ b/pkg/coredata/mesure_state.go @@ -15,7 +15,7 @@ package coredata import ( - "database/sql/driver" + "encoding" "fmt" ) @@ -32,6 +32,12 @@ const ( MeasureStateNotImplemented MeasureState = "NOT_IMPLEMENTED" ) +var ( + _ fmt.Stringer = MeasureState("") + _ encoding.TextMarshaler = MeasureState("") + _ encoding.TextUnmarshaler = (*MeasureState)(nil) +) + func MeasureStates() []MeasureState { return []MeasureState{ MeasureStateNotStarted, @@ -43,38 +49,36 @@ func MeasureStates() []MeasureState { } } -func (ms MeasureState) MarshalText() ([]byte, error) { - return []byte(ms), nil +func (v MeasureState) IsValid() bool { + switch v { + case + MeasureStateNotStarted, + MeasureStateInProgress, + MeasureStateNotApplicable, + MeasureStateImplemented, + MeasureStateUnknown, + MeasureStateNotImplemented: + return true + } + + return false } -func (ms *MeasureState) UnmarshalText(data []byte) error { - val := MeasureState(data) +func (v MeasureState) String() string { + return string(v) +} - switch val { - case MeasureStateNotStarted, MeasureStateInProgress, - MeasureStateNotApplicable, MeasureStateImplemented, - MeasureStateUnknown, MeasureStateNotImplemented: - *ms = val - default: - return fmt.Errorf("invalid MeasureState value: %q", val) +func (v MeasureState) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *MeasureState) UnmarshalText(text []byte) error { + val := MeasureState(text) + if !val.IsValid() { + return fmt.Errorf("invalid MeasureState value: %q", string(text)) } + *v = val + return nil } - -func (ms MeasureState) String() string { - return string(ms) -} - -func (ms *MeasureState) Scan(value any) error { - val, ok := value.(string) - if !ok { - return fmt.Errorf("invalid scan source for MeasureState, expected string got %T", value) - } - - return ms.UnmarshalText([]byte(val)) -} - -func (ms MeasureState) Value() (driver.Value, error) { - return string(ms), nil -} diff --git a/pkg/coredata/mfa_status.go b/pkg/coredata/mfa_status.go index 1265ff826..d41780628 100644 --- a/pkg/coredata/mfa_status.go +++ b/pkg/coredata/mfa_status.go @@ -15,7 +15,7 @@ package coredata import ( - "database/sql/driver" + "encoding" "fmt" ) @@ -27,6 +27,12 @@ const ( MFAStatusUnknown MFAStatus = "UNKNOWN" ) +var ( + _ fmt.Stringer = MFAStatus("") + _ encoding.TextMarshaler = MFAStatus("") + _ encoding.TextUnmarshaler = (*MFAStatus)(nil) +) + func MFAStatuses() []MFAStatus { return []MFAStatus{ MFAStatusEnabled, @@ -35,36 +41,33 @@ func MFAStatuses() []MFAStatus { } } -func (m MFAStatus) String() string { - return string(m) +func (v MFAStatus) IsValid() bool { + switch v { + case + MFAStatusEnabled, + MFAStatusDisabled, + MFAStatusUnknown: + return true + } + + return false } -func (m *MFAStatus) Scan(value any) error { - var str string +func (v MFAStatus) String() string { + return string(v) +} - switch v := value.(type) { - case string: - str = v - case []byte: - str = string(v) - default: - return fmt.Errorf("cannot scan MFAStatus: unsupported type %T", value) +func (v MFAStatus) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *MFAStatus) UnmarshalText(text []byte) error { + val := MFAStatus(text) + if !val.IsValid() { + return fmt.Errorf("invalid MFAStatus value: %q", string(text)) } - switch str { - case "ENABLED": - *m = MFAStatusEnabled - case "DISABLED": - *m = MFAStatusDisabled - case "UNKNOWN": - *m = MFAStatusUnknown - default: - return fmt.Errorf("cannot parse MFAStatus: invalid value %q", str) - } + *v = val return nil } - -func (m MFAStatus) Value() (driver.Value, error) { - return m.String(), nil -} diff --git a/pkg/coredata/oauth2_claim.go b/pkg/coredata/oauth2_claim.go index 1e8058ddd..4b0e3efe0 100644 --- a/pkg/coredata/oauth2_claim.go +++ b/pkg/coredata/oauth2_claim.go @@ -14,7 +14,10 @@ package coredata -import "fmt" +import ( + "encoding" + "fmt" +) type OAuth2Claim string @@ -32,9 +35,32 @@ const ( OAuth2ClaimName OAuth2Claim = "name" ) -func (c OAuth2Claim) IsValid() bool { - switch c { - case OAuth2ClaimIssuer, +var ( + _ fmt.Stringer = OAuth2Claim("") + _ encoding.TextMarshaler = OAuth2Claim("") + _ encoding.TextUnmarshaler = (*OAuth2Claim)(nil) +) + +func OAuth2Claims() []OAuth2Claim { + return []OAuth2Claim{ + OAuth2ClaimIssuer, + OAuth2ClaimSubject, + OAuth2ClaimAudience, + OAuth2ClaimExpiration, + OAuth2ClaimIssuedAt, + OAuth2ClaimAuthTime, + OAuth2ClaimNonce, + OAuth2ClaimAtHash, + OAuth2ClaimEmail, + OAuth2ClaimEmailVerified, + OAuth2ClaimName, + } +} + +func (v OAuth2Claim) IsValid() bool { + switch v { + case + OAuth2ClaimIssuer, OAuth2ClaimSubject, OAuth2ClaimAudience, OAuth2ClaimExpiration, @@ -51,17 +77,21 @@ func (c OAuth2Claim) IsValid() bool { return false } -func (c OAuth2Claim) String() string { return string(c) } +func (v OAuth2Claim) String() string { + return string(v) +} -func (c *OAuth2Claim) UnmarshalText(text []byte) error { - *c = OAuth2Claim(text) - if !c.IsValid() { - return fmt.Errorf("%s is not a valid OAuth2Claim", string(text)) +func (v OAuth2Claim) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *OAuth2Claim) UnmarshalText(text []byte) error { + val := OAuth2Claim(text) + if !val.IsValid() { + return fmt.Errorf("invalid OAuth2Claim value: %q", string(text)) } + *v = val + return nil } - -func (c OAuth2Claim) MarshalText() ([]byte, error) { - return []byte(c.String()), nil -} diff --git a/pkg/coredata/oauth2_client_order_field.go b/pkg/coredata/oauth2_client_order_field.go index 9ea87c1a6..b9b31d96b 100644 --- a/pkg/coredata/oauth2_client_order_field.go +++ b/pkg/coredata/oauth2_client_order_field.go @@ -14,7 +14,12 @@ package coredata -import "fmt" +import ( + "encoding" + "fmt" + + "go.probo.inc/probo/pkg/page" +) type OAuth2ClientOrderField string @@ -22,6 +27,48 @@ const ( OAuth2ClientOrderFieldCreatedAt OAuth2ClientOrderField = "CREATED_AT" ) +var ( + _ page.OrderField = OAuth2ClientOrderField("") + _ fmt.Stringer = OAuth2ClientOrderField("") + _ encoding.TextMarshaler = OAuth2ClientOrderField("") + _ encoding.TextUnmarshaler = (*OAuth2ClientOrderField)(nil) +) + +func OAuth2ClientOrderFields() []OAuth2ClientOrderField { + return []OAuth2ClientOrderField{ + OAuth2ClientOrderFieldCreatedAt, + } +} + +func (v OAuth2ClientOrderField) IsValid() bool { + switch v { + case + OAuth2ClientOrderFieldCreatedAt: + return true + } + + return false +} + +func (v OAuth2ClientOrderField) String() string { + return string(v) +} + +func (v OAuth2ClientOrderField) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *OAuth2ClientOrderField) UnmarshalText(text []byte) error { + val := OAuth2ClientOrderField(text) + if !val.IsValid() { + return fmt.Errorf("invalid OAuth2ClientOrderField value: %q", string(text)) + } + + *v = val + + return nil +} + func (f OAuth2ClientOrderField) Column() string { switch f { case OAuth2ClientOrderFieldCreatedAt: @@ -30,29 +77,3 @@ func (f OAuth2ClientOrderField) Column() string { panic(fmt.Sprintf("unsupported order by: %s", f)) } - -func (f OAuth2ClientOrderField) IsValid() bool { - switch f { - case OAuth2ClientOrderFieldCreatedAt: - return true - } - - return false -} - -func (f OAuth2ClientOrderField) String() string { - return string(f) -} - -func (f *OAuth2ClientOrderField) UnmarshalText(text []byte) error { - *f = OAuth2ClientOrderField(text) - if !f.IsValid() { - return fmt.Errorf("%s is not a valid OAuth2ClientOrderField", string(text)) - } - - return nil -} - -func (f OAuth2ClientOrderField) MarshalText() ([]byte, error) { - return []byte(f.String()), nil -} diff --git a/pkg/coredata/oauth2_client_token_endpoint_auth_method.go b/pkg/coredata/oauth2_client_token_endpoint_auth_method.go index 8909b5adb..353e2aa13 100644 --- a/pkg/coredata/oauth2_client_token_endpoint_auth_method.go +++ b/pkg/coredata/oauth2_client_token_endpoint_auth_method.go @@ -14,7 +14,10 @@ package coredata -import "fmt" +import ( + "encoding" + "fmt" +) type OAuth2ClientTokenEndpointAuthMethod string @@ -24,9 +27,24 @@ const ( OAuth2ClientTokenEndpointAuthMethodNone OAuth2ClientTokenEndpointAuthMethod = "none" ) -func (m OAuth2ClientTokenEndpointAuthMethod) IsValid() bool { - switch m { - case OAuth2ClientTokenEndpointAuthMethodClientSecretBasic, +var ( + _ fmt.Stringer = OAuth2ClientTokenEndpointAuthMethod("") + _ encoding.TextMarshaler = OAuth2ClientTokenEndpointAuthMethod("") + _ encoding.TextUnmarshaler = (*OAuth2ClientTokenEndpointAuthMethod)(nil) +) + +func OAuth2ClientTokenEndpointAuthMethods() []OAuth2ClientTokenEndpointAuthMethod { + return []OAuth2ClientTokenEndpointAuthMethod{ + OAuth2ClientTokenEndpointAuthMethodClientSecretBasic, + OAuth2ClientTokenEndpointAuthMethodClientSecretPost, + OAuth2ClientTokenEndpointAuthMethodNone, + } +} + +func (v OAuth2ClientTokenEndpointAuthMethod) IsValid() bool { + switch v { + case + OAuth2ClientTokenEndpointAuthMethodClientSecretBasic, OAuth2ClientTokenEndpointAuthMethodClientSecretPost, OAuth2ClientTokenEndpointAuthMethodNone: return true @@ -35,17 +53,21 @@ func (m OAuth2ClientTokenEndpointAuthMethod) IsValid() bool { return false } -func (m OAuth2ClientTokenEndpointAuthMethod) String() string { return string(m) } +func (v OAuth2ClientTokenEndpointAuthMethod) String() string { + return string(v) +} -func (m *OAuth2ClientTokenEndpointAuthMethod) UnmarshalText(text []byte) error { - *m = OAuth2ClientTokenEndpointAuthMethod(text) - if !m.IsValid() { - return fmt.Errorf("%s is not a valid OAuth2ClientTokenEndpointAuthMethod", string(text)) +func (v OAuth2ClientTokenEndpointAuthMethod) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *OAuth2ClientTokenEndpointAuthMethod) UnmarshalText(text []byte) error { + val := OAuth2ClientTokenEndpointAuthMethod(text) + if !val.IsValid() { + return fmt.Errorf("invalid OAuth2ClientTokenEndpointAuthMethod value: %q", string(text)) } + *v = val + return nil } - -func (m OAuth2ClientTokenEndpointAuthMethod) MarshalText() ([]byte, error) { - return []byte(m.String()), nil -} diff --git a/pkg/coredata/oauth2_client_visibility.go b/pkg/coredata/oauth2_client_visibility.go index 83a2b460f..5596ce85f 100644 --- a/pkg/coredata/oauth2_client_visibility.go +++ b/pkg/coredata/oauth2_client_visibility.go @@ -14,7 +14,10 @@ package coredata -import "fmt" +import ( + "encoding" + "fmt" +) type OAuth2ClientVisibility string @@ -23,26 +26,45 @@ const ( OAuth2ClientVisibilityPublic OAuth2ClientVisibility = "public" ) +var ( + _ fmt.Stringer = OAuth2ClientVisibility("") + _ encoding.TextMarshaler = OAuth2ClientVisibility("") + _ encoding.TextUnmarshaler = (*OAuth2ClientVisibility)(nil) +) + +func OAuth2ClientVisibilities() []OAuth2ClientVisibility { + return []OAuth2ClientVisibility{ + OAuth2ClientVisibilityPrivate, + OAuth2ClientVisibilityPublic, + } +} + func (v OAuth2ClientVisibility) IsValid() bool { switch v { - case OAuth2ClientVisibilityPrivate, OAuth2ClientVisibilityPublic: + case + OAuth2ClientVisibilityPrivate, + OAuth2ClientVisibilityPublic: return true } return false } -func (v OAuth2ClientVisibility) String() string { return string(v) } - -func (v *OAuth2ClientVisibility) UnmarshalText(text []byte) error { - *v = OAuth2ClientVisibility(text) - if !v.IsValid() { - return fmt.Errorf("%s is not a valid OAuth2ClientVisibility", string(text)) - } - - return nil +func (v OAuth2ClientVisibility) String() string { + return string(v) } func (v OAuth2ClientVisibility) MarshalText() ([]byte, error) { return []byte(v.String()), nil } + +func (v *OAuth2ClientVisibility) UnmarshalText(text []byte) error { + val := OAuth2ClientVisibility(text) + if !val.IsValid() { + return fmt.Errorf("invalid OAuth2ClientVisibility value: %q", string(text)) + } + + *v = val + + return nil +} diff --git a/pkg/coredata/oauth2_code_challenge_method.go b/pkg/coredata/oauth2_code_challenge_method.go index 4478e2682..80fd2731f 100644 --- a/pkg/coredata/oauth2_code_challenge_method.go +++ b/pkg/coredata/oauth2_code_challenge_method.go @@ -14,7 +14,10 @@ package coredata -import "fmt" +import ( + "encoding" + "fmt" +) type OAuth2CodeChallengeMethod string @@ -22,26 +25,43 @@ const ( OAuth2CodeChallengeMethodS256 OAuth2CodeChallengeMethod = "S256" ) -func (m OAuth2CodeChallengeMethod) IsValid() bool { - switch m { - case OAuth2CodeChallengeMethodS256: +var ( + _ fmt.Stringer = OAuth2CodeChallengeMethod("") + _ encoding.TextMarshaler = OAuth2CodeChallengeMethod("") + _ encoding.TextUnmarshaler = (*OAuth2CodeChallengeMethod)(nil) +) + +func OAuth2CodeChallengeMethods() []OAuth2CodeChallengeMethod { + return []OAuth2CodeChallengeMethod{ + OAuth2CodeChallengeMethodS256, + } +} + +func (v OAuth2CodeChallengeMethod) IsValid() bool { + switch v { + case + OAuth2CodeChallengeMethodS256: return true } return false } -func (m OAuth2CodeChallengeMethod) String() string { return string(m) } +func (v OAuth2CodeChallengeMethod) String() string { + return string(v) +} -func (m *OAuth2CodeChallengeMethod) UnmarshalText(text []byte) error { - *m = OAuth2CodeChallengeMethod(text) - if !m.IsValid() { - return fmt.Errorf("%s is not a valid OAuth2CodeChallengeMethod", string(text)) +func (v OAuth2CodeChallengeMethod) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *OAuth2CodeChallengeMethod) UnmarshalText(text []byte) error { + val := OAuth2CodeChallengeMethod(text) + if !val.IsValid() { + return fmt.Errorf("invalid OAuth2CodeChallengeMethod value: %q", string(text)) } + *v = val + return nil } - -func (m OAuth2CodeChallengeMethod) MarshalText() ([]byte, error) { - return []byte(m.String()), nil -} diff --git a/pkg/coredata/oauth2_consent_order_field.go b/pkg/coredata/oauth2_consent_order_field.go index e2a60b3bf..9302f6279 100644 --- a/pkg/coredata/oauth2_consent_order_field.go +++ b/pkg/coredata/oauth2_consent_order_field.go @@ -14,7 +14,12 @@ package coredata -import "fmt" +import ( + "encoding" + "fmt" + + "go.probo.inc/probo/pkg/page" +) type OAuth2ConsentOrderField string @@ -22,6 +27,48 @@ const ( OAuth2ConsentOrderFieldCreatedAt OAuth2ConsentOrderField = "CREATED_AT" ) +var ( + _ page.OrderField = OAuth2ConsentOrderField("") + _ fmt.Stringer = OAuth2ConsentOrderField("") + _ encoding.TextMarshaler = OAuth2ConsentOrderField("") + _ encoding.TextUnmarshaler = (*OAuth2ConsentOrderField)(nil) +) + +func OAuth2ConsentOrderFields() []OAuth2ConsentOrderField { + return []OAuth2ConsentOrderField{ + OAuth2ConsentOrderFieldCreatedAt, + } +} + +func (v OAuth2ConsentOrderField) IsValid() bool { + switch v { + case + OAuth2ConsentOrderFieldCreatedAt: + return true + } + + return false +} + +func (v OAuth2ConsentOrderField) String() string { + return string(v) +} + +func (v OAuth2ConsentOrderField) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *OAuth2ConsentOrderField) UnmarshalText(text []byte) error { + val := OAuth2ConsentOrderField(text) + if !val.IsValid() { + return fmt.Errorf("invalid OAuth2ConsentOrderField value: %q", string(text)) + } + + *v = val + + return nil +} + func (f OAuth2ConsentOrderField) Column() string { switch f { case OAuth2ConsentOrderFieldCreatedAt: @@ -30,27 +77,3 @@ func (f OAuth2ConsentOrderField) Column() string { panic(fmt.Sprintf("unsupported order by: %s", f)) } - -func (f OAuth2ConsentOrderField) IsValid() bool { - switch f { - case OAuth2ConsentOrderFieldCreatedAt: - return true - } - - return false -} - -func (f OAuth2ConsentOrderField) String() string { return string(f) } - -func (f *OAuth2ConsentOrderField) UnmarshalText(text []byte) error { - *f = OAuth2ConsentOrderField(text) - if !f.IsValid() { - return fmt.Errorf("%s is not a valid OAuth2ConsentOrderField", string(text)) - } - - return nil -} - -func (f OAuth2ConsentOrderField) MarshalText() ([]byte, error) { - return []byte(f.String()), nil -} diff --git a/pkg/coredata/oauth2_device_code_status.go b/pkg/coredata/oauth2_device_code_status.go index d03510be4..f7e176a9f 100644 --- a/pkg/coredata/oauth2_device_code_status.go +++ b/pkg/coredata/oauth2_device_code_status.go @@ -14,7 +14,10 @@ package coredata -import "fmt" +import ( + "encoding" + "fmt" +) type OAuth2DeviceCodeStatus string @@ -25,9 +28,25 @@ const ( OAuth2DeviceCodeStatusExpired OAuth2DeviceCodeStatus = "expired" ) -func (s OAuth2DeviceCodeStatus) IsValid() bool { - switch s { - case OAuth2DeviceCodeStatusPending, +var ( + _ fmt.Stringer = OAuth2DeviceCodeStatus("") + _ encoding.TextMarshaler = OAuth2DeviceCodeStatus("") + _ encoding.TextUnmarshaler = (*OAuth2DeviceCodeStatus)(nil) +) + +func OAuth2DeviceCodeStatuses() []OAuth2DeviceCodeStatus { + return []OAuth2DeviceCodeStatus{ + OAuth2DeviceCodeStatusPending, + OAuth2DeviceCodeStatusAuthorized, + OAuth2DeviceCodeStatusDenied, + OAuth2DeviceCodeStatusExpired, + } +} + +func (v OAuth2DeviceCodeStatus) IsValid() bool { + switch v { + case + OAuth2DeviceCodeStatusPending, OAuth2DeviceCodeStatusAuthorized, OAuth2DeviceCodeStatusDenied, OAuth2DeviceCodeStatusExpired: @@ -37,17 +56,21 @@ func (s OAuth2DeviceCodeStatus) IsValid() bool { return false } -func (s OAuth2DeviceCodeStatus) String() string { return string(s) } +func (v OAuth2DeviceCodeStatus) String() string { + return string(v) +} -func (s *OAuth2DeviceCodeStatus) UnmarshalText(text []byte) error { - *s = OAuth2DeviceCodeStatus(text) - if !s.IsValid() { - return fmt.Errorf("%s is not a valid OAuth2DeviceCodeStatus", string(text)) +func (v OAuth2DeviceCodeStatus) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *OAuth2DeviceCodeStatus) UnmarshalText(text []byte) error { + val := OAuth2DeviceCodeStatus(text) + if !val.IsValid() { + return fmt.Errorf("invalid OAuth2DeviceCodeStatus value: %q", string(text)) } + *v = val + return nil } - -func (s OAuth2DeviceCodeStatus) MarshalText() ([]byte, error) { - return []byte(s.String()), nil -} diff --git a/pkg/coredata/oauth2_grant_type.go b/pkg/coredata/oauth2_grant_type.go index 7d8003bb6..0ecd1c828 100644 --- a/pkg/coredata/oauth2_grant_type.go +++ b/pkg/coredata/oauth2_grant_type.go @@ -14,7 +14,10 @@ package coredata -import "fmt" +import ( + "encoding" + "fmt" +) type ( OAuth2GrantType string @@ -27,9 +30,16 @@ const ( OAuth2GrantTypeDeviceCode OAuth2GrantType = "urn:ietf:params:oauth:grant-type:device_code" ) -func (g OAuth2GrantType) IsValid() bool { - switch g { - case OAuth2GrantTypeAuthorizationCode, +var ( + _ fmt.Stringer = OAuth2GrantType("") + _ encoding.TextMarshaler = OAuth2GrantType("") + _ encoding.TextUnmarshaler = (*OAuth2GrantType)(nil) +) + +func (v OAuth2GrantType) IsValid() bool { + switch v { + case + OAuth2GrantTypeAuthorizationCode, OAuth2GrantTypeRefreshToken, OAuth2GrantTypeDeviceCode: return true @@ -38,17 +48,21 @@ func (g OAuth2GrantType) IsValid() bool { return false } -func (g OAuth2GrantType) String() string { return string(g) } +func (v OAuth2GrantType) String() string { + return string(v) +} -func (g *OAuth2GrantType) UnmarshalText(text []byte) error { - *g = OAuth2GrantType(text) - if !g.IsValid() { - return fmt.Errorf("%s is not a valid OAuth2GrantType", string(text)) +func (v OAuth2GrantType) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *OAuth2GrantType) UnmarshalText(text []byte) error { + val := OAuth2GrantType(text) + if !val.IsValid() { + return fmt.Errorf("invalid OAuth2GrantType value: %q", string(text)) } + *v = val + return nil } - -func (g OAuth2GrantType) MarshalText() ([]byte, error) { - return []byte(g.String()), nil -} diff --git a/pkg/coredata/oauth2_response_type.go b/pkg/coredata/oauth2_response_type.go index 1e2a58843..11ce523ff 100644 --- a/pkg/coredata/oauth2_response_type.go +++ b/pkg/coredata/oauth2_response_type.go @@ -14,7 +14,10 @@ package coredata -import "fmt" +import ( + "encoding" + "fmt" +) type ( OAuth2ResponseType string @@ -25,26 +28,37 @@ const ( OAuth2ResponseTypeCode OAuth2ResponseType = "code" ) -func (r OAuth2ResponseType) IsValid() bool { - switch r { - case OAuth2ResponseTypeCode: +var ( + _ fmt.Stringer = OAuth2ResponseType("") + _ encoding.TextMarshaler = OAuth2ResponseType("") + _ encoding.TextUnmarshaler = (*OAuth2ResponseType)(nil) +) + +func (v OAuth2ResponseType) IsValid() bool { + switch v { + case + OAuth2ResponseTypeCode: return true } return false } -func (r OAuth2ResponseType) String() string { return string(r) } +func (v OAuth2ResponseType) String() string { + return string(v) +} -func (r *OAuth2ResponseType) UnmarshalText(text []byte) error { - *r = OAuth2ResponseType(text) - if !r.IsValid() { - return fmt.Errorf("%s is not a valid OAuth2ResponseType", string(text)) +func (v OAuth2ResponseType) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *OAuth2ResponseType) UnmarshalText(text []byte) error { + val := OAuth2ResponseType(text) + if !val.IsValid() { + return fmt.Errorf("invalid OAuth2ResponseType value: %q", string(text)) } + *v = val + return nil } - -func (r OAuth2ResponseType) MarshalText() ([]byte, error) { - return []byte(r.String()), nil -} diff --git a/pkg/coredata/oauth2_scope.go b/pkg/coredata/oauth2_scope.go index c602b786d..c86bbdaad 100644 --- a/pkg/coredata/oauth2_scope.go +++ b/pkg/coredata/oauth2_scope.go @@ -15,6 +15,7 @@ package coredata import ( + "encoding" "fmt" "iter" "slices" @@ -33,28 +34,42 @@ const ( OAuth2ScopeOfflineAccess OAuth2Scope = "offline_access" ) -func (s OAuth2Scope) IsValid() bool { - switch s { - case OAuth2ScopeOpenID, OAuth2ScopeProfile, OAuth2ScopeEmail, OAuth2ScopeOfflineAccess: +var ( + _ fmt.Stringer = OAuth2Scope("") + _ encoding.TextMarshaler = OAuth2Scope("") + _ encoding.TextUnmarshaler = (*OAuth2Scope)(nil) +) + +func (v OAuth2Scope) IsValid() bool { + switch v { + case + OAuth2ScopeOpenID, + OAuth2ScopeProfile, + OAuth2ScopeEmail, + OAuth2ScopeOfflineAccess: return true } return false } -func (s OAuth2Scope) String() string { return string(s) } - -func (s *OAuth2Scope) UnmarshalText(text []byte) error { - *s = OAuth2Scope(text) - if !s.IsValid() { - return fmt.Errorf("%s is not a valid OAuth2Scope", string(text)) - } - - return nil +func (v OAuth2Scope) String() string { + return string(v) } -func (s OAuth2Scope) MarshalText() ([]byte, error) { - return []byte(s.String()), nil +func (v OAuth2Scope) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *OAuth2Scope) UnmarshalText(text []byte) error { + val := OAuth2Scope(text) + if !val.IsValid() { + return fmt.Errorf("invalid OAuth2Scope value: %q", string(text)) + } + + *v = val + + return nil } func (s OAuth2Scopes) All() iter.Seq2[int, OAuth2Scope] { diff --git a/pkg/coredata/oauth2_signing_algorithm.go b/pkg/coredata/oauth2_signing_algorithm.go index b2a1f2a1f..c07eadafd 100644 --- a/pkg/coredata/oauth2_signing_algorithm.go +++ b/pkg/coredata/oauth2_signing_algorithm.go @@ -14,7 +14,10 @@ package coredata -import "fmt" +import ( + "encoding" + "fmt" +) type OAuth2SigningAlgorithm string @@ -22,26 +25,43 @@ const ( OAuth2SigningAlgorithmRS256 OAuth2SigningAlgorithm = "RS256" ) -func (a OAuth2SigningAlgorithm) IsValid() bool { - switch a { - case OAuth2SigningAlgorithmRS256: +var ( + _ fmt.Stringer = OAuth2SigningAlgorithm("") + _ encoding.TextMarshaler = OAuth2SigningAlgorithm("") + _ encoding.TextUnmarshaler = (*OAuth2SigningAlgorithm)(nil) +) + +func OAuth2SigningAlgorithms() []OAuth2SigningAlgorithm { + return []OAuth2SigningAlgorithm{ + OAuth2SigningAlgorithmRS256, + } +} + +func (v OAuth2SigningAlgorithm) IsValid() bool { + switch v { + case + OAuth2SigningAlgorithmRS256: return true } return false } -func (a OAuth2SigningAlgorithm) String() string { return string(a) } +func (v OAuth2SigningAlgorithm) String() string { + return string(v) +} -func (a *OAuth2SigningAlgorithm) UnmarshalText(text []byte) error { - *a = OAuth2SigningAlgorithm(text) - if !a.IsValid() { - return fmt.Errorf("%s is not a valid OAuth2SigningAlgorithm", string(text)) +func (v OAuth2SigningAlgorithm) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *OAuth2SigningAlgorithm) UnmarshalText(text []byte) error { + val := OAuth2SigningAlgorithm(text) + if !val.IsValid() { + return fmt.Errorf("invalid OAuth2SigningAlgorithm value: %q", string(text)) } + *v = val + return nil } - -func (a OAuth2SigningAlgorithm) MarshalText() ([]byte, error) { - return []byte(a.String()), nil -} diff --git a/pkg/coredata/oauth2_subject_type.go b/pkg/coredata/oauth2_subject_type.go index 8b42b3622..c0126af4c 100644 --- a/pkg/coredata/oauth2_subject_type.go +++ b/pkg/coredata/oauth2_subject_type.go @@ -14,7 +14,10 @@ package coredata -import "fmt" +import ( + "encoding" + "fmt" +) type OAuth2SubjectType string @@ -22,26 +25,43 @@ const ( OAuth2SubjectTypePublic OAuth2SubjectType = "public" ) -func (s OAuth2SubjectType) IsValid() bool { - switch s { - case OAuth2SubjectTypePublic: +var ( + _ fmt.Stringer = OAuth2SubjectType("") + _ encoding.TextMarshaler = OAuth2SubjectType("") + _ encoding.TextUnmarshaler = (*OAuth2SubjectType)(nil) +) + +func OAuth2SubjectTypes() []OAuth2SubjectType { + return []OAuth2SubjectType{ + OAuth2SubjectTypePublic, + } +} + +func (v OAuth2SubjectType) IsValid() bool { + switch v { + case + OAuth2SubjectTypePublic: return true } return false } -func (s OAuth2SubjectType) String() string { return string(s) } +func (v OAuth2SubjectType) String() string { + return string(v) +} -func (s *OAuth2SubjectType) UnmarshalText(text []byte) error { - *s = OAuth2SubjectType(text) - if !s.IsValid() { - return fmt.Errorf("%s is not a valid OAuth2SubjectType", string(text)) +func (v OAuth2SubjectType) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *OAuth2SubjectType) UnmarshalText(text []byte) error { + val := OAuth2SubjectType(text) + if !val.IsValid() { + return fmt.Errorf("invalid OAuth2SubjectType value: %q", string(text)) } + *v = val + return nil } - -func (s OAuth2SubjectType) MarshalText() ([]byte, error) { - return []byte(s.String()), nil -} diff --git a/pkg/coredata/oauth2_token_type_hint.go b/pkg/coredata/oauth2_token_type_hint.go index bdb016b2f..7444d2dcd 100644 --- a/pkg/coredata/oauth2_token_type_hint.go +++ b/pkg/coredata/oauth2_token_type_hint.go @@ -14,7 +14,10 @@ package coredata -import "fmt" +import ( + "encoding" + "fmt" +) type OAuth2TokenTypeHint string @@ -23,9 +26,23 @@ const ( OAuth2TokenTypeHintRefreshToken OAuth2TokenTypeHint = "refresh_token" ) -func (h OAuth2TokenTypeHint) IsValid() bool { - switch h { - case OAuth2TokenTypeHintAccessToken, +var ( + _ fmt.Stringer = OAuth2TokenTypeHint("") + _ encoding.TextMarshaler = OAuth2TokenTypeHint("") + _ encoding.TextUnmarshaler = (*OAuth2TokenTypeHint)(nil) +) + +func OAuth2TokenTypeHints() []OAuth2TokenTypeHint { + return []OAuth2TokenTypeHint{ + OAuth2TokenTypeHintAccessToken, + OAuth2TokenTypeHintRefreshToken, + } +} + +func (v OAuth2TokenTypeHint) IsValid() bool { + switch v { + case + OAuth2TokenTypeHintAccessToken, OAuth2TokenTypeHintRefreshToken: return true } @@ -33,17 +50,21 @@ func (h OAuth2TokenTypeHint) IsValid() bool { return false } -func (h OAuth2TokenTypeHint) String() string { return string(h) } +func (v OAuth2TokenTypeHint) String() string { + return string(v) +} -func (h *OAuth2TokenTypeHint) UnmarshalText(text []byte) error { - *h = OAuth2TokenTypeHint(text) - if !h.IsValid() { - return fmt.Errorf("%s is not a valid OAuth2TokenTypeHint", string(text)) +func (v OAuth2TokenTypeHint) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *OAuth2TokenTypeHint) UnmarshalText(text []byte) error { + val := OAuth2TokenTypeHint(text) + if !val.IsValid() { + return fmt.Errorf("invalid OAuth2TokenTypeHint value: %q", string(text)) } + *v = val + return nil } - -func (h OAuth2TokenTypeHint) MarshalText() ([]byte, error) { - return []byte(h.String()), nil -} diff --git a/pkg/coredata/obligation_order_field.go b/pkg/coredata/obligation_order_field.go index 00fc7d25c..a2dcfed3b 100644 --- a/pkg/coredata/obligation_order_field.go +++ b/pkg/coredata/obligation_order_field.go @@ -15,7 +15,10 @@ package coredata import ( + "encoding" "fmt" + + "go.probo.inc/probo/pkg/page" ) type ObligationOrderField string @@ -27,28 +30,54 @@ const ( ObligationOrderFieldStatus ObligationOrderField = "STATUS" ) +var ( + _ page.OrderField = ObligationOrderField("") + _ fmt.Stringer = ObligationOrderField("") + _ encoding.TextMarshaler = ObligationOrderField("") + _ encoding.TextUnmarshaler = (*ObligationOrderField)(nil) +) + +func ObligationOrderFields() []ObligationOrderField { + return []ObligationOrderField{ + ObligationOrderFieldCreatedAt, + ObligationOrderFieldLastReviewDate, + ObligationOrderFieldDueDate, + ObligationOrderFieldStatus, + } +} + +func (v ObligationOrderField) IsValid() bool { + switch v { + case + ObligationOrderFieldCreatedAt, + ObligationOrderFieldLastReviewDate, + ObligationOrderFieldDueDate, + ObligationOrderFieldStatus: + return true + } + + return false +} + +func (v ObligationOrderField) String() string { + return string(v) +} + +func (v ObligationOrderField) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *ObligationOrderField) UnmarshalText(text []byte) error { + val := ObligationOrderField(text) + if !val.IsValid() { + return fmt.Errorf("invalid ObligationOrderField value: %q", string(text)) + } + + *v = val + + return nil +} + func (p ObligationOrderField) Column() string { return string(p) } - -func (p ObligationOrderField) String() string { - return string(p) -} - -func (p ObligationOrderField) MarshalText() ([]byte, error) { - return []byte(p.String()), nil -} - -func (p *ObligationOrderField) UnmarshalText(text []byte) error { - val := string(text) - switch val { - case string(ObligationOrderFieldCreatedAt), - string(ObligationOrderFieldLastReviewDate), - string(ObligationOrderFieldDueDate), - string(ObligationOrderFieldStatus): - *p = ObligationOrderField(val) - return nil - } - - return fmt.Errorf("invalid ObligationOrderField value: %q", val) -} diff --git a/pkg/coredata/obligation_status.go b/pkg/coredata/obligation_status.go index df7a81bba..7a9edf122 100644 --- a/pkg/coredata/obligation_status.go +++ b/pkg/coredata/obligation_status.go @@ -15,7 +15,7 @@ package coredata import ( - "database/sql/driver" + "encoding" "fmt" ) @@ -27,6 +27,12 @@ const ( ObligationStatusCompliant ObligationStatus = "COMPLIANT" ) +var ( + _ fmt.Stringer = ObligationStatus("") + _ encoding.TextMarshaler = ObligationStatus("") + _ encoding.TextUnmarshaler = (*ObligationStatus)(nil) +) + func ObligationStatuses() []ObligationStatus { return []ObligationStatus{ ObligationStatusNonCompliant, @@ -35,36 +41,33 @@ func ObligationStatuses() []ObligationStatus { } } -func (os ObligationStatus) String() string { - return string(os) +func (v ObligationStatus) IsValid() bool { + switch v { + case + ObligationStatusNonCompliant, + ObligationStatusPartiallyCompliant, + ObligationStatusCompliant: + return true + } + + return false } -func (os *ObligationStatus) Scan(value any) error { - var s string +func (v ObligationStatus) String() string { + return string(v) +} - switch v := value.(type) { - case string: - s = v - case []byte: - s = string(v) - default: - return fmt.Errorf("unsupported type for ObligationStatus: %T", value) +func (v ObligationStatus) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *ObligationStatus) UnmarshalText(text []byte) error { + val := ObligationStatus(text) + if !val.IsValid() { + return fmt.Errorf("invalid ObligationStatus value: %q", string(text)) } - switch s { - case "NON_COMPLIANT": - *os = ObligationStatusNonCompliant - case "PARTIALLY_COMPLIANT": - *os = ObligationStatusPartiallyCompliant - case "COMPLIANT": - *os = ObligationStatusCompliant - default: - return fmt.Errorf("invalid ObligationStatus value: %q", s) - } + *v = val return nil } - -func (os ObligationStatus) Value() (driver.Value, error) { - return os.String(), nil -} diff --git a/pkg/coredata/obligation_type.go b/pkg/coredata/obligation_type.go index cc935c444..d20c1daaf 100644 --- a/pkg/coredata/obligation_type.go +++ b/pkg/coredata/obligation_type.go @@ -15,7 +15,7 @@ package coredata import ( - "database/sql/driver" + "encoding" "fmt" ) @@ -26,6 +26,12 @@ const ( ObligationTypeContractual ObligationType = "CONTRACTUAL" ) +var ( + _ fmt.Stringer = ObligationType("") + _ encoding.TextMarshaler = ObligationType("") + _ encoding.TextUnmarshaler = (*ObligationType)(nil) +) + func ObligationTypes() []ObligationType { return []ObligationType{ ObligationTypeLegal, @@ -33,34 +39,32 @@ func ObligationTypes() []ObligationType { } } -func (ot ObligationType) String() string { - return string(ot) +func (v ObligationType) IsValid() bool { + switch v { + case + ObligationTypeLegal, + ObligationTypeContractual: + return true + } + + return false } -func (ot *ObligationType) Scan(value any) error { - var s string +func (v ObligationType) String() string { + return string(v) +} - switch v := value.(type) { - case string: - s = v - case []byte: - s = string(v) - default: - return fmt.Errorf("unsupported type for ObligationType: %T", value) +func (v ObligationType) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *ObligationType) UnmarshalText(text []byte) error { + val := ObligationType(text) + if !val.IsValid() { + return fmt.Errorf("invalid ObligationType value: %q", string(text)) } - switch s { - case "LEGAL": - *ot = ObligationTypeLegal - case "CONTRACTUAL": - *ot = ObligationTypeContractual - default: - return fmt.Errorf("invalid ObligationType value: %q", s) - } + *v = val return nil } - -func (ot ObligationType) Value() (driver.Value, error) { - return ot.String(), nil -} diff --git a/pkg/coredata/oidc_provider.go b/pkg/coredata/oidc_provider.go index 66dc08ac5..370689aaf 100644 --- a/pkg/coredata/oidc_provider.go +++ b/pkg/coredata/oidc_provider.go @@ -14,7 +14,10 @@ package coredata -import "fmt" +import ( + "encoding" + "fmt" +) type OIDCProvider string @@ -23,26 +26,45 @@ const ( OIDCProviderMicrosoft OIDCProvider = "MICROSOFT" ) -func (p OIDCProvider) IsValid() bool { - switch p { - case OIDCProviderGoogle, OIDCProviderMicrosoft: +var ( + _ fmt.Stringer = OIDCProvider("") + _ encoding.TextMarshaler = OIDCProvider("") + _ encoding.TextUnmarshaler = (*OIDCProvider)(nil) +) + +func OIDCProviders() []OIDCProvider { + return []OIDCProvider{ + OIDCProviderGoogle, + OIDCProviderMicrosoft, + } +} + +func (v OIDCProvider) IsValid() bool { + switch v { + case + OIDCProviderGoogle, + OIDCProviderMicrosoft: return true } return false } -func (p OIDCProvider) String() string { return string(p) } +func (v OIDCProvider) String() string { + return string(v) +} -func (p *OIDCProvider) UnmarshalText(text []byte) error { - *p = OIDCProvider(text) - if !p.IsValid() { - return fmt.Errorf("%s is not a valid OIDCProvider", string(text)) +func (v OIDCProvider) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *OIDCProvider) UnmarshalText(text []byte) error { + val := OIDCProvider(text) + if !val.IsValid() { + return fmt.Errorf("invalid OIDCProvider value: %q", string(text)) } + *v = val + return nil } - -func (p OIDCProvider) MarshalText() ([]byte, error) { - return []byte(p.String()), nil -} diff --git a/pkg/coredata/organization_order_field.go b/pkg/coredata/organization_order_field.go index 18b892055..fb699afed 100644 --- a/pkg/coredata/organization_order_field.go +++ b/pkg/coredata/organization_order_field.go @@ -14,6 +14,13 @@ package coredata +import ( + "encoding" + "fmt" + + "go.probo.inc/probo/pkg/page" +) + type ( OrganizationOrderField string ) @@ -24,19 +31,52 @@ const ( OrganizationOrderFieldUpdatedAt OrganizationOrderField = "UPDATED_AT" ) +var ( + _ page.OrderField = OrganizationOrderField("") + _ fmt.Stringer = OrganizationOrderField("") + _ encoding.TextMarshaler = OrganizationOrderField("") + _ encoding.TextUnmarshaler = (*OrganizationOrderField)(nil) +) + +func OrganizationOrderFields() []OrganizationOrderField { + return []OrganizationOrderField{ + OrganizationOrderFieldName, + OrganizationOrderFieldCreatedAt, + OrganizationOrderFieldUpdatedAt, + } +} + +func (v OrganizationOrderField) IsValid() bool { + switch v { + case + OrganizationOrderFieldName, + OrganizationOrderFieldCreatedAt, + OrganizationOrderFieldUpdatedAt: + return true + } + + return false +} + +func (v OrganizationOrderField) String() string { + return string(v) +} + +func (v OrganizationOrderField) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *OrganizationOrderField) UnmarshalText(text []byte) error { + val := OrganizationOrderField(text) + if !val.IsValid() { + return fmt.Errorf("invalid OrganizationOrderField value: %q", string(text)) + } + + *v = val + + return nil +} + func (p OrganizationOrderField) Column() string { return string(p) } - -func (p OrganizationOrderField) String() string { - return string(p) -} - -func (p OrganizationOrderField) MarshalText() ([]byte, error) { - return []byte(p.String()), nil -} - -func (p *OrganizationOrderField) UnmarshalText(text []byte) error { - *p = OrganizationOrderField(text) - return nil -} diff --git a/pkg/coredata/personal_api_key_order_field.go b/pkg/coredata/personal_api_key_order_field.go index bf79e560b..49224ec69 100644 --- a/pkg/coredata/personal_api_key_order_field.go +++ b/pkg/coredata/personal_api_key_order_field.go @@ -14,6 +14,13 @@ package coredata +import ( + "encoding" + "fmt" + + "go.probo.inc/probo/pkg/page" +) + type ( PersonalAPIKeyOrderField string ) @@ -22,19 +29,48 @@ const ( PersonalAPIKeyOrderFieldCreatedAt PersonalAPIKeyOrderField = "CREATED_AT" ) +var ( + _ page.OrderField = PersonalAPIKeyOrderField("") + _ fmt.Stringer = PersonalAPIKeyOrderField("") + _ encoding.TextMarshaler = PersonalAPIKeyOrderField("") + _ encoding.TextUnmarshaler = (*PersonalAPIKeyOrderField)(nil) +) + +func PersonalAPIKeyOrderFields() []PersonalAPIKeyOrderField { + return []PersonalAPIKeyOrderField{ + PersonalAPIKeyOrderFieldCreatedAt, + } +} + +func (v PersonalAPIKeyOrderField) IsValid() bool { + switch v { + case + PersonalAPIKeyOrderFieldCreatedAt: + return true + } + + return false +} + +func (v PersonalAPIKeyOrderField) String() string { + return string(v) +} + +func (v PersonalAPIKeyOrderField) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *PersonalAPIKeyOrderField) UnmarshalText(text []byte) error { + val := PersonalAPIKeyOrderField(text) + if !val.IsValid() { + return fmt.Errorf("invalid PersonalAPIKeyOrderField value: %q", string(text)) + } + + *v = val + + return nil +} + func (p PersonalAPIKeyOrderField) Column() string { return string(p) } - -func (p PersonalAPIKeyOrderField) String() string { - return string(p) -} - -func (p PersonalAPIKeyOrderField) MarshalText() ([]byte, error) { - return []byte(p.String()), nil -} - -func (p *PersonalAPIKeyOrderField) UnmarshalText(text []byte) error { - *p = PersonalAPIKeyOrderField(text) - return nil -} diff --git a/pkg/coredata/processing_activity_data_protection_impact_assessment.go b/pkg/coredata/processing_activity_data_protection_impact_assessment.go index 14e8c680a..9fec342c8 100644 --- a/pkg/coredata/processing_activity_data_protection_impact_assessment.go +++ b/pkg/coredata/processing_activity_data_protection_impact_assessment.go @@ -15,7 +15,7 @@ package coredata import ( - "database/sql/driver" + "encoding" "fmt" ) @@ -26,6 +26,12 @@ const ( ProcessingActivityDataProtectionImpactAssessmentNotNeeded ProcessingActivityDataProtectionImpactAssessment = "NOT_NEEDED" ) +var ( + _ fmt.Stringer = ProcessingActivityDataProtectionImpactAssessment("") + _ encoding.TextMarshaler = ProcessingActivityDataProtectionImpactAssessment("") + _ encoding.TextUnmarshaler = (*ProcessingActivityDataProtectionImpactAssessment)(nil) +) + func ProcessingActivityDataProtectionImpactAssessments() []ProcessingActivityDataProtectionImpactAssessment { return []ProcessingActivityDataProtectionImpactAssessment{ ProcessingActivityDataProtectionImpactAssessmentNeeded, @@ -33,34 +39,32 @@ func ProcessingActivityDataProtectionImpactAssessments() []ProcessingActivityDat } } -func (p ProcessingActivityDataProtectionImpactAssessment) String() string { - return string(p) +func (v ProcessingActivityDataProtectionImpactAssessment) IsValid() bool { + switch v { + case + ProcessingActivityDataProtectionImpactAssessmentNeeded, + ProcessingActivityDataProtectionImpactAssessmentNotNeeded: + return true + } + + return false } -func (p *ProcessingActivityDataProtectionImpactAssessment) Scan(value any) error { - var s string +func (v ProcessingActivityDataProtectionImpactAssessment) String() string { + return string(v) +} - switch v := value.(type) { - case string: - s = v - case []byte: - s = string(v) - default: - return fmt.Errorf("unsupported type for ProcessingActivityDataProtectionImpactAssessment: %T", value) +func (v ProcessingActivityDataProtectionImpactAssessment) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *ProcessingActivityDataProtectionImpactAssessment) UnmarshalText(text []byte) error { + val := ProcessingActivityDataProtectionImpactAssessment(text) + if !val.IsValid() { + return fmt.Errorf("invalid ProcessingActivityDataProtectionImpactAssessment value: %q", string(text)) } - switch s { - case "NEEDED": - *p = ProcessingActivityDataProtectionImpactAssessmentNeeded - case "NOT_NEEDED": - *p = ProcessingActivityDataProtectionImpactAssessmentNotNeeded - default: - return fmt.Errorf("invalid ProcessingActivityDataProtectionImpactAssessment value: %q", s) - } + *v = val return nil } - -func (p ProcessingActivityDataProtectionImpactAssessment) Value() (driver.Value, error) { - return p.String(), nil -} diff --git a/pkg/coredata/processing_activity_lawful_basis.go b/pkg/coredata/processing_activity_lawful_basis.go index d57eb8525..aea31456c 100644 --- a/pkg/coredata/processing_activity_lawful_basis.go +++ b/pkg/coredata/processing_activity_lawful_basis.go @@ -15,7 +15,7 @@ package coredata import ( - "database/sql/driver" + "encoding" "fmt" ) @@ -30,6 +30,12 @@ const ( ProcessingActivityLawfulBasisPublicTask ProcessingActivityLawfulBasis = "PUBLIC_TASK" ) +var ( + _ fmt.Stringer = ProcessingActivityLawfulBasis("") + _ encoding.TextMarshaler = ProcessingActivityLawfulBasis("") + _ encoding.TextUnmarshaler = (*ProcessingActivityLawfulBasis)(nil) +) + func ProcessingActivityLawfulBases() []ProcessingActivityLawfulBasis { return []ProcessingActivityLawfulBasis{ ProcessingActivityLawfulBasisLegitimateInterest, @@ -41,42 +47,36 @@ func ProcessingActivityLawfulBases() []ProcessingActivityLawfulBasis { } } -func (p ProcessingActivityLawfulBasis) String() string { - return string(p) +func (v ProcessingActivityLawfulBasis) IsValid() bool { + switch v { + case + ProcessingActivityLawfulBasisLegitimateInterest, + ProcessingActivityLawfulBasisConsent, + ProcessingActivityLawfulBasisContractualNecessity, + ProcessingActivityLawfulBasisLegalObligation, + ProcessingActivityLawfulBasisVitalInterests, + ProcessingActivityLawfulBasisPublicTask: + return true + } + + return false } -func (p *ProcessingActivityLawfulBasis) Scan(value any) error { - var s string +func (v ProcessingActivityLawfulBasis) String() string { + return string(v) +} - switch v := value.(type) { - case string: - s = v - case []byte: - s = string(v) - default: - return fmt.Errorf("unsupported type for ProcessingActivityLawfulBasis: %T", value) +func (v ProcessingActivityLawfulBasis) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *ProcessingActivityLawfulBasis) UnmarshalText(text []byte) error { + val := ProcessingActivityLawfulBasis(text) + if !val.IsValid() { + return fmt.Errorf("invalid ProcessingActivityLawfulBasis value: %q", string(text)) } - switch s { - case "LEGITIMATE_INTEREST": - *p = ProcessingActivityLawfulBasisLegitimateInterest - case "CONSENT": - *p = ProcessingActivityLawfulBasisConsent - case "CONTRACTUAL_NECESSITY": - *p = ProcessingActivityLawfulBasisContractualNecessity - case "LEGAL_OBLIGATION": - *p = ProcessingActivityLawfulBasisLegalObligation - case "VITAL_INTERESTS": - *p = ProcessingActivityLawfulBasisVitalInterests - case "PUBLIC_TASK": - *p = ProcessingActivityLawfulBasisPublicTask - default: - return fmt.Errorf("invalid ProcessingActivityLawfulBasis value: %q", s) - } + *v = val return nil } - -func (p ProcessingActivityLawfulBasis) Value() (driver.Value, error) { - return p.String(), nil -} diff --git a/pkg/coredata/processing_activity_order_field.go b/pkg/coredata/processing_activity_order_field.go index b81c85d6f..c189ef5e7 100644 --- a/pkg/coredata/processing_activity_order_field.go +++ b/pkg/coredata/processing_activity_order_field.go @@ -15,7 +15,10 @@ package coredata import ( + "encoding" "fmt" + + "go.probo.inc/probo/pkg/page" ) type ProcessingActivityOrderField string @@ -25,26 +28,50 @@ const ( ProcessingActivityOrderFieldName ProcessingActivityOrderField = "NAME" ) +var ( + _ page.OrderField = ProcessingActivityOrderField("") + _ fmt.Stringer = ProcessingActivityOrderField("") + _ encoding.TextMarshaler = ProcessingActivityOrderField("") + _ encoding.TextUnmarshaler = (*ProcessingActivityOrderField)(nil) +) + +func ProcessingActivityOrderFields() []ProcessingActivityOrderField { + return []ProcessingActivityOrderField{ + ProcessingActivityOrderFieldCreatedAt, + ProcessingActivityOrderFieldName, + } +} + +func (v ProcessingActivityOrderField) IsValid() bool { + switch v { + case + ProcessingActivityOrderFieldCreatedAt, + ProcessingActivityOrderFieldName: + return true + } + + return false +} + +func (v ProcessingActivityOrderField) String() string { + return string(v) +} + +func (v ProcessingActivityOrderField) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *ProcessingActivityOrderField) UnmarshalText(text []byte) error { + val := ProcessingActivityOrderField(text) + if !val.IsValid() { + return fmt.Errorf("invalid ProcessingActivityOrderField value: %q", string(text)) + } + + *v = val + + return nil +} + func (p ProcessingActivityOrderField) Column() string { return string(p) } - -func (p ProcessingActivityOrderField) String() string { - return string(p) -} - -func (p ProcessingActivityOrderField) MarshalText() ([]byte, error) { - return []byte(p.String()), nil -} - -func (p *ProcessingActivityOrderField) UnmarshalText(text []byte) error { - val := string(text) - switch val { - case string(ProcessingActivityOrderFieldCreatedAt), - string(ProcessingActivityOrderFieldName): - *p = ProcessingActivityOrderField(val) - return nil - } - - return fmt.Errorf("invalid ProcessingActivityOrderField value: %q", val) -} diff --git a/pkg/coredata/processing_activity_role.go b/pkg/coredata/processing_activity_role.go index 3c46db2c9..2b0bb1ab3 100644 --- a/pkg/coredata/processing_activity_role.go +++ b/pkg/coredata/processing_activity_role.go @@ -15,7 +15,7 @@ package coredata import ( - "database/sql/driver" + "encoding" "fmt" ) @@ -26,6 +26,12 @@ const ( ProcessingActivityRoleProcessor ProcessingActivityRole = "PROCESSOR" ) +var ( + _ fmt.Stringer = ProcessingActivityRole("") + _ encoding.TextMarshaler = ProcessingActivityRole("") + _ encoding.TextUnmarshaler = (*ProcessingActivityRole)(nil) +) + func ProcessingActivityRoles() []ProcessingActivityRole { return []ProcessingActivityRole{ ProcessingActivityRoleController, @@ -33,34 +39,32 @@ func ProcessingActivityRoles() []ProcessingActivityRole { } } -func (p ProcessingActivityRole) String() string { - return string(p) +func (v ProcessingActivityRole) IsValid() bool { + switch v { + case + ProcessingActivityRoleController, + ProcessingActivityRoleProcessor: + return true + } + + return false } -func (p *ProcessingActivityRole) Scan(value any) error { - var s string +func (v ProcessingActivityRole) String() string { + return string(v) +} - switch v := value.(type) { - case string: - s = v - case []byte: - s = string(v) - default: - return fmt.Errorf("unsupported type for ProcessingActivityRole: %T", value) +func (v ProcessingActivityRole) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *ProcessingActivityRole) UnmarshalText(text []byte) error { + val := ProcessingActivityRole(text) + if !val.IsValid() { + return fmt.Errorf("invalid ProcessingActivityRole value: %q", string(text)) } - switch s { - case "CONTROLLER": - *p = ProcessingActivityRoleController - case "PROCESSOR": - *p = ProcessingActivityRoleProcessor - default: - return fmt.Errorf("invalid ProcessingActivityRole value: %q", s) - } + *v = val return nil } - -func (p ProcessingActivityRole) Value() (driver.Value, error) { - return p.String(), nil -} diff --git a/pkg/coredata/processing_activity_special_or_criminal_data.go b/pkg/coredata/processing_activity_special_or_criminal_data.go index 19ff0977b..a87998a6a 100644 --- a/pkg/coredata/processing_activity_special_or_criminal_data.go +++ b/pkg/coredata/processing_activity_special_or_criminal_data.go @@ -15,7 +15,7 @@ package coredata import ( - "database/sql/driver" + "encoding" "fmt" ) @@ -27,6 +27,12 @@ const ( ProcessingActivitySpecialOrCriminalDatumPossible ProcessingActivitySpecialOrCriminalDatum = "POSSIBLE" ) +var ( + _ fmt.Stringer = ProcessingActivitySpecialOrCriminalDatum("") + _ encoding.TextMarshaler = ProcessingActivitySpecialOrCriminalDatum("") + _ encoding.TextUnmarshaler = (*ProcessingActivitySpecialOrCriminalDatum)(nil) +) + func ProcessingActivitySpecialOrCriminalData() []ProcessingActivitySpecialOrCriminalDatum { return []ProcessingActivitySpecialOrCriminalDatum{ ProcessingActivitySpecialOrCriminalDatumYes, @@ -35,36 +41,33 @@ func ProcessingActivitySpecialOrCriminalData() []ProcessingActivitySpecialOrCrim } } -func (p ProcessingActivitySpecialOrCriminalDatum) String() string { - return string(p) +func (v ProcessingActivitySpecialOrCriminalDatum) IsValid() bool { + switch v { + case + ProcessingActivitySpecialOrCriminalDatumYes, + ProcessingActivitySpecialOrCriminalDatumNo, + ProcessingActivitySpecialOrCriminalDatumPossible: + return true + } + + return false } -func (p *ProcessingActivitySpecialOrCriminalDatum) Scan(value any) error { - var s string +func (v ProcessingActivitySpecialOrCriminalDatum) String() string { + return string(v) +} - switch v := value.(type) { - case string: - s = v - case []byte: - s = string(v) - default: - return fmt.Errorf("unsupported type for ProcessingActivitySpecialOrCriminalDatum: %T", value) +func (v ProcessingActivitySpecialOrCriminalDatum) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *ProcessingActivitySpecialOrCriminalDatum) UnmarshalText(text []byte) error { + val := ProcessingActivitySpecialOrCriminalDatum(text) + if !val.IsValid() { + return fmt.Errorf("invalid ProcessingActivitySpecialOrCriminalDatum value: %q", string(text)) } - switch s { - case "YES": - *p = ProcessingActivitySpecialOrCriminalDatumYes - case "NO": - *p = ProcessingActivitySpecialOrCriminalDatumNo - case "POSSIBLE": - *p = ProcessingActivitySpecialOrCriminalDatumPossible - default: - return fmt.Errorf("invalid ProcessingActivitySpecialOrCriminalDatum value: %q", s) - } + *v = val return nil } - -func (p ProcessingActivitySpecialOrCriminalDatum) Value() (driver.Value, error) { - return p.String(), nil -} diff --git a/pkg/coredata/processing_activity_transfer_impact_assessment.go b/pkg/coredata/processing_activity_transfer_impact_assessment.go index c8fcf6154..9f17623ac 100644 --- a/pkg/coredata/processing_activity_transfer_impact_assessment.go +++ b/pkg/coredata/processing_activity_transfer_impact_assessment.go @@ -15,7 +15,7 @@ package coredata import ( - "database/sql/driver" + "encoding" "fmt" ) @@ -26,6 +26,12 @@ const ( ProcessingActivityTransferImpactAssessmentNotNeeded ProcessingActivityTransferImpactAssessment = "NOT_NEEDED" ) +var ( + _ fmt.Stringer = ProcessingActivityTransferImpactAssessment("") + _ encoding.TextMarshaler = ProcessingActivityTransferImpactAssessment("") + _ encoding.TextUnmarshaler = (*ProcessingActivityTransferImpactAssessment)(nil) +) + func ProcessingActivityTransferImpactAssessments() []ProcessingActivityTransferImpactAssessment { return []ProcessingActivityTransferImpactAssessment{ ProcessingActivityTransferImpactAssessmentNeeded, @@ -33,34 +39,32 @@ func ProcessingActivityTransferImpactAssessments() []ProcessingActivityTransferI } } -func (p ProcessingActivityTransferImpactAssessment) String() string { - return string(p) +func (v ProcessingActivityTransferImpactAssessment) IsValid() bool { + switch v { + case + ProcessingActivityTransferImpactAssessmentNeeded, + ProcessingActivityTransferImpactAssessmentNotNeeded: + return true + } + + return false } -func (p *ProcessingActivityTransferImpactAssessment) Scan(value any) error { - var s string +func (v ProcessingActivityTransferImpactAssessment) String() string { + return string(v) +} - switch v := value.(type) { - case string: - s = v - case []byte: - s = string(v) - default: - return fmt.Errorf("unsupported type for ProcessingActivityTransferImpactAssessment: %T", value) +func (v ProcessingActivityTransferImpactAssessment) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *ProcessingActivityTransferImpactAssessment) UnmarshalText(text []byte) error { + val := ProcessingActivityTransferImpactAssessment(text) + if !val.IsValid() { + return fmt.Errorf("invalid ProcessingActivityTransferImpactAssessment value: %q", string(text)) } - switch s { - case "NEEDED": - *p = ProcessingActivityTransferImpactAssessmentNeeded - case "NOT_NEEDED": - *p = ProcessingActivityTransferImpactAssessmentNotNeeded - default: - return fmt.Errorf("invalid ProcessingActivityTransferImpactAssessment value: %q", s) - } + *v = val return nil } - -func (p ProcessingActivityTransferImpactAssessment) Value() (driver.Value, error) { - return p.String(), nil -} diff --git a/pkg/coredata/processing_activity_transfer_safeguards.go b/pkg/coredata/processing_activity_transfer_safeguards.go index 768c4fc3c..fbd8d7bf6 100644 --- a/pkg/coredata/processing_activity_transfer_safeguards.go +++ b/pkg/coredata/processing_activity_transfer_safeguards.go @@ -15,7 +15,7 @@ package coredata import ( - "database/sql/driver" + "encoding" "fmt" ) @@ -30,6 +30,12 @@ const ( ProcessingActivityTransferSafeguardCertificationMechanisms ProcessingActivityTransferSafeguard = "CERTIFICATION_MECHANISMS" ) +var ( + _ fmt.Stringer = ProcessingActivityTransferSafeguard("") + _ encoding.TextMarshaler = ProcessingActivityTransferSafeguard("") + _ encoding.TextUnmarshaler = (*ProcessingActivityTransferSafeguard)(nil) +) + func ProcessingActivityTransferSafeguards() []ProcessingActivityTransferSafeguard { return []ProcessingActivityTransferSafeguard{ ProcessingActivityTransferSafeguardStandardContractualClauses, @@ -41,42 +47,36 @@ func ProcessingActivityTransferSafeguards() []ProcessingActivityTransferSafeguar } } -func (p ProcessingActivityTransferSafeguard) String() string { - return string(p) +func (v ProcessingActivityTransferSafeguard) IsValid() bool { + switch v { + case + ProcessingActivityTransferSafeguardStandardContractualClauses, + ProcessingActivityTransferSafeguardBindingCorporateRules, + ProcessingActivityTransferSafeguardAdequacyDecision, + ProcessingActivityTransferSafeguardDerogations, + ProcessingActivityTransferSafeguardCodesOfConduct, + ProcessingActivityTransferSafeguardCertificationMechanisms: + return true + } + + return false } -func (p *ProcessingActivityTransferSafeguard) Scan(value any) error { - var s string +func (v ProcessingActivityTransferSafeguard) String() string { + return string(v) +} - switch v := value.(type) { - case string: - s = v - case []byte: - s = string(v) - default: - return fmt.Errorf("unsupported type for ProcessingActivityTransferSafeguard: %T", value) +func (v ProcessingActivityTransferSafeguard) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *ProcessingActivityTransferSafeguard) UnmarshalText(text []byte) error { + val := ProcessingActivityTransferSafeguard(text) + if !val.IsValid() { + return fmt.Errorf("invalid ProcessingActivityTransferSafeguard value: %q", string(text)) } - switch s { - case "STANDARD_CONTRACTUAL_CLAUSES": - *p = ProcessingActivityTransferSafeguardStandardContractualClauses - case "BINDING_CORPORATE_RULES": - *p = ProcessingActivityTransferSafeguardBindingCorporateRules - case "ADEQUACY_DECISION": - *p = ProcessingActivityTransferSafeguardAdequacyDecision - case "DEROGATIONS": - *p = ProcessingActivityTransferSafeguardDerogations - case "CODES_OF_CONDUCT": - *p = ProcessingActivityTransferSafeguardCodesOfConduct - case "CERTIFICATION_MECHANISMS": - *p = ProcessingActivityTransferSafeguardCertificationMechanisms - default: - return fmt.Errorf("invalid ProcessingActivityTransferSafeguard value: %q", s) - } + *v = val return nil } - -func (p ProcessingActivityTransferSafeguard) Value() (driver.Value, error) { - return p.String(), nil -} diff --git a/pkg/coredata/profile_source.go b/pkg/coredata/profile_source.go index 8d2cde77f..417d7012a 100644 --- a/pkg/coredata/profile_source.go +++ b/pkg/coredata/profile_source.go @@ -15,7 +15,7 @@ package coredata import ( - "database/sql/driver" + "encoding" "fmt" ) @@ -27,36 +27,47 @@ const ( ProfileSourceSCIM ProfileSource = "SCIM" ) -func (s ProfileSource) String() string { - return string(s) +var ( + _ fmt.Stringer = ProfileSource("") + _ encoding.TextMarshaler = ProfileSource("") + _ encoding.TextUnmarshaler = (*ProfileSource)(nil) +) + +func ProfileSources() []ProfileSource { + return []ProfileSource{ + ProfileSourceManual, + ProfileSourceSAML, + ProfileSourceSCIM, + } } -func (s *ProfileSource) Scan(value any) error { - var str string - - switch v := value.(type) { - case string: - str = v - case []byte: - str = string(v) - default: - return fmt.Errorf("unsupported type for ProfileSource: %T", value) +func (v ProfileSource) IsValid() bool { + switch v { + case + ProfileSourceManual, + ProfileSourceSAML, + ProfileSourceSCIM: + return true } - switch str { - case "MANUAL": - *s = ProfileSourceManual - case "SAML": - *s = ProfileSourceSAML - case "SCIM": - *s = ProfileSourceSCIM - default: - return fmt.Errorf("invalid ProfileSource value: %q", str) + return false +} + +func (v ProfileSource) String() string { + return string(v) +} + +func (v ProfileSource) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *ProfileSource) UnmarshalText(text []byte) error { + val := ProfileSource(text) + if !val.IsValid() { + return fmt.Errorf("invalid ProfileSource value: %q", string(text)) } + *v = val + return nil } - -func (s ProfileSource) Value() (driver.Value, error) { - return s.String(), nil -} diff --git a/pkg/coredata/profile_state.go b/pkg/coredata/profile_state.go index 2b08480d9..8993b0386 100644 --- a/pkg/coredata/profile_state.go +++ b/pkg/coredata/profile_state.go @@ -15,7 +15,7 @@ package coredata import ( - "database/sql/driver" + "encoding" "fmt" ) @@ -26,34 +26,45 @@ const ( ProfileStateInactive ProfileState = "INACTIVE" ) -func (s ProfileState) String() string { - return string(s) +var ( + _ fmt.Stringer = ProfileState("") + _ encoding.TextMarshaler = ProfileState("") + _ encoding.TextUnmarshaler = (*ProfileState)(nil) +) + +func ProfileStates() []ProfileState { + return []ProfileState{ + ProfileStateActive, + ProfileStateInactive, + } } -func (s *ProfileState) Scan(value any) error { - var str string - - switch v := value.(type) { - case string: - str = v - case []byte: - str = string(v) - default: - return fmt.Errorf("unsupported type for ProfileState: %T", value) +func (v ProfileState) IsValid() bool { + switch v { + case + ProfileStateActive, + ProfileStateInactive: + return true } - switch str { - case "ACTIVE": - *s = ProfileStateActive - case "INACTIVE": - *s = ProfileStateInactive - default: - return fmt.Errorf("invalid ProfileState value: %q", str) + return false +} + +func (v ProfileState) String() string { + return string(v) +} + +func (v ProfileState) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *ProfileState) UnmarshalText(text []byte) error { + val := ProfileState(text) + if !val.IsValid() { + return fmt.Errorf("invalid ProfileState value: %q", string(text)) } + *v = val + return nil } - -func (s ProfileState) Value() (driver.Value, error) { - return s.String(), nil -} diff --git a/pkg/coredata/regulation.go b/pkg/coredata/regulation.go index 9a6a57649..44946571f 100644 --- a/pkg/coredata/regulation.go +++ b/pkg/coredata/regulation.go @@ -15,8 +15,7 @@ package coredata import ( - "database/sql/driver" - "encoding/json" + "encoding" "fmt" ) @@ -40,8 +39,15 @@ const ( RegulationPDPL Regulation = "PDPL" ) +var ( + _ fmt.Stringer = Regulation("") + _ encoding.TextMarshaler = Regulation("") + _ encoding.TextUnmarshaler = (*Regulation)(nil) +) + func Regulations() []Regulation { return []Regulation{ + RegulationNone, RegulationGDPR, RegulationUKGDPR, RegulationFADP, @@ -59,6 +65,49 @@ func Regulations() []Regulation { } } +func (v Regulation) IsValid() bool { + switch v { + case + RegulationNone, + RegulationGDPR, + RegulationUKGDPR, + RegulationFADP, + RegulationCCPA, + RegulationPIPEDA, + RegulationLGPD, + RegulationLFPDPPP, + RegulationPOPIA, + RegulationPDPA, + RegulationPIPL, + RegulationPIPA, + RegulationAPPI, + RegulationDPDP, + RegulationPDPL: + return true + } + + return false +} + +func (v Regulation) String() string { + return string(v) +} + +func (v Regulation) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *Regulation) UnmarshalText(text []byte) error { + val := Regulation(text) + if !val.IsValid() { + return fmt.Errorf("invalid Regulation value: %q", string(text)) + } + + *v = val + + return nil +} + func ParseRegulation(s string) (Regulation, error) { switch Regulation(s) { case RegulationNone: @@ -95,61 +144,3 @@ func ParseRegulation(s string) (Regulation, error) { return "", fmt.Errorf("invalid Regulation value: %q", s) } } - -func (r Regulation) String() string { - return string(r) -} - -func (r *Regulation) Scan(value any) error { - var v string - - switch val := value.(type) { - case string: - v = val - case []byte: - v = string(val) - default: - return fmt.Errorf("unsupported type for Regulation: %T", value) - } - - parsed, err := ParseRegulation(v) - if err != nil { - return err - } - - *r = parsed - - return nil -} - -func (r Regulation) Value() (driver.Value, error) { - if r == RegulationNone { - return "", nil - } - - if _, err := ParseRegulation(string(r)); err != nil { - return nil, fmt.Errorf("invalid Regulation: %s", r) - } - - return string(r), nil -} - -func (r Regulation) MarshalJSON() ([]byte, error) { - return json.Marshal(string(r)) -} - -func (r *Regulation) UnmarshalJSON(data []byte) error { - var s string - if err := json.Unmarshal(data, &s); err != nil { - return fmt.Errorf("cannot unmarshal Regulation: %w", err) - } - - parsed, err := ParseRegulation(s) - if err != nil { - return err - } - - *r = parsed - - return nil -} diff --git a/pkg/coredata/report_order_field.go b/pkg/coredata/report_order_field.go index 2ff7e0635..cecaa427a 100644 --- a/pkg/coredata/report_order_field.go +++ b/pkg/coredata/report_order_field.go @@ -14,6 +14,13 @@ package coredata +import ( + "encoding" + "fmt" + + "go.probo.inc/probo/pkg/page" +) + type ( ReportOrderField string ) @@ -22,19 +29,48 @@ const ( ReportOrderFieldID ReportOrderField = "ID" ) +var ( + _ page.OrderField = ReportOrderField("") + _ fmt.Stringer = ReportOrderField("") + _ encoding.TextMarshaler = ReportOrderField("") + _ encoding.TextUnmarshaler = (*ReportOrderField)(nil) +) + +func ReportOrderFields() []ReportOrderField { + return []ReportOrderField{ + ReportOrderFieldID, + } +} + +func (v ReportOrderField) IsValid() bool { + switch v { + case + ReportOrderFieldID: + return true + } + + return false +} + +func (v ReportOrderField) String() string { + return string(v) +} + +func (v ReportOrderField) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *ReportOrderField) UnmarshalText(text []byte) error { + val := ReportOrderField(text) + if !val.IsValid() { + return fmt.Errorf("invalid ReportOrderField value: %q", string(text)) + } + + *v = val + + return nil +} + func (p ReportOrderField) Column() string { return string(p) } - -func (p ReportOrderField) String() string { - return string(p) -} - -func (p ReportOrderField) MarshalText() ([]byte, error) { - return []byte(p.String()), nil -} - -func (p *ReportOrderField) UnmarshalText(text []byte) error { - *p = ReportOrderField(text) - return nil -} diff --git a/pkg/coredata/rights_request_order_field.go b/pkg/coredata/rights_request_order_field.go index bde2e7070..c515af258 100644 --- a/pkg/coredata/rights_request_order_field.go +++ b/pkg/coredata/rights_request_order_field.go @@ -14,6 +14,13 @@ package coredata +import ( + "encoding" + "fmt" + + "go.probo.inc/probo/pkg/page" +) + type RightsRequestOrderField string const ( @@ -23,19 +30,54 @@ const ( RightsRequestOrderFieldType RightsRequestOrderField = "TYPE" ) +var ( + _ page.OrderField = RightsRequestOrderField("") + _ fmt.Stringer = RightsRequestOrderField("") + _ encoding.TextMarshaler = RightsRequestOrderField("") + _ encoding.TextUnmarshaler = (*RightsRequestOrderField)(nil) +) + +func RightsRequestOrderFields() []RightsRequestOrderField { + return []RightsRequestOrderField{ + RightsRequestOrderFieldCreatedAt, + RightsRequestOrderFieldDeadline, + RightsRequestOrderFieldState, + RightsRequestOrderFieldType, + } +} + +func (v RightsRequestOrderField) IsValid() bool { + switch v { + case + RightsRequestOrderFieldCreatedAt, + RightsRequestOrderFieldDeadline, + RightsRequestOrderFieldState, + RightsRequestOrderFieldType: + return true + } + + return false +} + +func (v RightsRequestOrderField) String() string { + return string(v) +} + +func (v RightsRequestOrderField) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *RightsRequestOrderField) UnmarshalText(text []byte) error { + val := RightsRequestOrderField(text) + if !val.IsValid() { + return fmt.Errorf("invalid RightsRequestOrderField value: %q", string(text)) + } + + *v = val + + return nil +} + func (p RightsRequestOrderField) Column() string { return string(p) } - -func (p RightsRequestOrderField) String() string { - return string(p) -} - -func (p RightsRequestOrderField) MarshalText() ([]byte, error) { - return []byte(p.String()), nil -} - -func (p *RightsRequestOrderField) UnmarshalText(text []byte) error { - *p = RightsRequestOrderField(text) - return nil -} diff --git a/pkg/coredata/rights_request_state.go b/pkg/coredata/rights_request_state.go index c0ac0748b..2b2610e44 100644 --- a/pkg/coredata/rights_request_state.go +++ b/pkg/coredata/rights_request_state.go @@ -15,7 +15,7 @@ package coredata import ( - "database/sql/driver" + "encoding" "fmt" ) @@ -27,6 +27,12 @@ const ( RightsRequestStateDone RightsRequestState = "DONE" ) +var ( + _ fmt.Stringer = RightsRequestState("") + _ encoding.TextMarshaler = RightsRequestState("") + _ encoding.TextUnmarshaler = (*RightsRequestState)(nil) +) + func RightsRequestStates() []RightsRequestState { return []RightsRequestState{ RightsRequestStateTodo, @@ -35,36 +41,33 @@ func RightsRequestStates() []RightsRequestState { } } -func (rrs RightsRequestState) String() string { - return string(rrs) +func (v RightsRequestState) IsValid() bool { + switch v { + case + RightsRequestStateTodo, + RightsRequestStateInProgress, + RightsRequestStateDone: + return true + } + + return false } -func (rrs *RightsRequestState) Scan(value any) error { - var s string +func (v RightsRequestState) String() string { + return string(v) +} - switch v := value.(type) { - case string: - s = v - case []byte: - s = string(v) - default: - return fmt.Errorf("unsupported type for RightsRequestState: %T", value) +func (v RightsRequestState) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *RightsRequestState) UnmarshalText(text []byte) error { + val := RightsRequestState(text) + if !val.IsValid() { + return fmt.Errorf("invalid RightsRequestState value: %q", string(text)) } - switch s { - case "TODO": - *rrs = RightsRequestStateTodo - case "IN_PROGRESS": - *rrs = RightsRequestStateInProgress - case "DONE": - *rrs = RightsRequestStateDone - default: - return fmt.Errorf("invalid RightsRequestState value: %q", s) - } + *v = val return nil } - -func (rrs RightsRequestState) Value() (driver.Value, error) { - return string(rrs), nil -} diff --git a/pkg/coredata/rights_request_type.go b/pkg/coredata/rights_request_type.go index fd5b17272..8890a2e9d 100644 --- a/pkg/coredata/rights_request_type.go +++ b/pkg/coredata/rights_request_type.go @@ -15,7 +15,7 @@ package coredata import ( - "database/sql/driver" + "encoding" "fmt" ) @@ -27,6 +27,12 @@ const ( RightsRequestTypePortability RightsRequestType = "PORTABILITY" ) +var ( + _ fmt.Stringer = RightsRequestType("") + _ encoding.TextMarshaler = RightsRequestType("") + _ encoding.TextUnmarshaler = (*RightsRequestType)(nil) +) + func RightsRequestTypes() []RightsRequestType { return []RightsRequestType{ RightsRequestTypeAccess, @@ -35,36 +41,33 @@ func RightsRequestTypes() []RightsRequestType { } } -func (rrt RightsRequestType) String() string { - return string(rrt) +func (v RightsRequestType) IsValid() bool { + switch v { + case + RightsRequestTypeAccess, + RightsRequestTypeDeletion, + RightsRequestTypePortability: + return true + } + + return false } -func (rrt *RightsRequestType) Scan(value any) error { - var s string +func (v RightsRequestType) String() string { + return string(v) +} - switch v := value.(type) { - case string: - s = v - case []byte: - s = string(v) - default: - return fmt.Errorf("unsupported type for RightsRequestType: %T", value) +func (v RightsRequestType) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *RightsRequestType) UnmarshalText(text []byte) error { + val := RightsRequestType(text) + if !val.IsValid() { + return fmt.Errorf("invalid RightsRequestType value: %q", string(text)) } - switch s { - case "ACCESS": - *rrt = RightsRequestTypeAccess - case "DELETION": - *rrt = RightsRequestTypeDeletion - case "PORTABILITY": - *rrt = RightsRequestTypePortability - default: - return fmt.Errorf("invalid RightsRequestType value: %q", s) - } + *v = val return nil } - -func (rrt RightsRequestType) Value() (driver.Value, error) { - return string(rrt), nil -} diff --git a/pkg/coredata/risk_assessment_node_order_field.go b/pkg/coredata/risk_assessment_node_order_field.go index 59a5b4eb9..5e2e81559 100644 --- a/pkg/coredata/risk_assessment_node_order_field.go +++ b/pkg/coredata/risk_assessment_node_order_field.go @@ -14,6 +14,13 @@ package coredata +import ( + "encoding" + "fmt" + + "go.probo.inc/probo/pkg/page" +) + type RiskAssessmentNodeOrderField string const ( @@ -21,14 +28,48 @@ const ( RiskAssessmentNodeOrderFieldName RiskAssessmentNodeOrderField = "NAME" ) -func (p RiskAssessmentNodeOrderField) Column() string { return string(p) } -func (p RiskAssessmentNodeOrderField) String() string { return string(p) } +var ( + _ page.OrderField = RiskAssessmentNodeOrderField("") + _ fmt.Stringer = RiskAssessmentNodeOrderField("") + _ encoding.TextMarshaler = RiskAssessmentNodeOrderField("") + _ encoding.TextUnmarshaler = (*RiskAssessmentNodeOrderField)(nil) +) -func (p RiskAssessmentNodeOrderField) MarshalText() ([]byte, error) { - return []byte(p.String()), nil +func RiskAssessmentNodeOrderFields() []RiskAssessmentNodeOrderField { + return []RiskAssessmentNodeOrderField{ + RiskAssessmentNodeOrderFieldCreatedAt, + RiskAssessmentNodeOrderFieldName, + } } -func (p *RiskAssessmentNodeOrderField) UnmarshalText(text []byte) error { - *p = RiskAssessmentNodeOrderField(text) +func (v RiskAssessmentNodeOrderField) IsValid() bool { + switch v { + case + RiskAssessmentNodeOrderFieldCreatedAt, + RiskAssessmentNodeOrderFieldName: + return true + } + + return false +} + +func (v RiskAssessmentNodeOrderField) String() string { + return string(v) +} + +func (v RiskAssessmentNodeOrderField) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *RiskAssessmentNodeOrderField) UnmarshalText(text []byte) error { + val := RiskAssessmentNodeOrderField(text) + if !val.IsValid() { + return fmt.Errorf("invalid RiskAssessmentNodeOrderField value: %q", string(text)) + } + + *v = val + return nil } + +func (p RiskAssessmentNodeOrderField) Column() string { return string(p) } diff --git a/pkg/coredata/risk_assessment_node_type.go b/pkg/coredata/risk_assessment_node_type.go index 12be517e2..9bad46806 100644 --- a/pkg/coredata/risk_assessment_node_type.go +++ b/pkg/coredata/risk_assessment_node_type.go @@ -15,7 +15,7 @@ package coredata import ( - "database/sql/driver" + "encoding" "fmt" ) @@ -28,6 +28,12 @@ const ( RiskAssessmentNodeTypeData RiskAssessmentNodeType = "DATA" ) +var ( + _ fmt.Stringer = RiskAssessmentNodeType("") + _ encoding.TextMarshaler = RiskAssessmentNodeType("") + _ encoding.TextUnmarshaler = (*RiskAssessmentNodeType)(nil) +) + func RiskAssessmentNodeTypes() []RiskAssessmentNodeType { return []RiskAssessmentNodeType{ RiskAssessmentNodeTypeEntity, @@ -37,42 +43,34 @@ func RiskAssessmentNodeTypes() []RiskAssessmentNodeType { } } -func (t RiskAssessmentNodeType) MarshalText() ([]byte, error) { - return []byte(t.String()), nil +func (v RiskAssessmentNodeType) IsValid() bool { + switch v { + case + RiskAssessmentNodeTypeEntity, + RiskAssessmentNodeTypeBoundary, + RiskAssessmentNodeTypeAsset, + RiskAssessmentNodeTypeData: + return true + } + + return false } -func (t *RiskAssessmentNodeType) UnmarshalText(data []byte) error { - val := string(data) +func (v RiskAssessmentNodeType) String() string { + return string(v) +} - switch val { - case RiskAssessmentNodeTypeEntity.String(): - *t = RiskAssessmentNodeTypeEntity - case RiskAssessmentNodeTypeBoundary.String(): - *t = RiskAssessmentNodeTypeBoundary - case RiskAssessmentNodeTypeAsset.String(): - *t = RiskAssessmentNodeTypeAsset - case RiskAssessmentNodeTypeData.String(): - *t = RiskAssessmentNodeTypeData - default: - return fmt.Errorf("invalid RiskAssessmentNodeType value: %q", val) +func (v RiskAssessmentNodeType) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *RiskAssessmentNodeType) UnmarshalText(text []byte) error { + val := RiskAssessmentNodeType(text) + if !val.IsValid() { + return fmt.Errorf("invalid RiskAssessmentNodeType value: %q", string(text)) } + *v = val + return nil } - -func (t RiskAssessmentNodeType) String() string { - return string(t) -} - -func (t *RiskAssessmentNodeType) Scan(value any) error { - val, ok := value.(string) - if !ok { - return fmt.Errorf("invalid scan source for RiskAssessmentNodeType, expected string got %T", value) - } - - return t.UnmarshalText([]byte(val)) -} - -func (t RiskAssessmentNodeType) Value() (driver.Value, error) { - return t.String(), nil -} diff --git a/pkg/coredata/risk_assessment_order_field.go b/pkg/coredata/risk_assessment_order_field.go index 8c14a44ba..9c90d5c27 100644 --- a/pkg/coredata/risk_assessment_order_field.go +++ b/pkg/coredata/risk_assessment_order_field.go @@ -14,6 +14,13 @@ package coredata +import ( + "encoding" + "fmt" + + "go.probo.inc/probo/pkg/page" +) + type RiskAssessmentOrderField string const ( @@ -21,19 +28,50 @@ const ( RiskAssessmentOrderFieldName RiskAssessmentOrderField = "NAME" ) +var ( + _ page.OrderField = RiskAssessmentOrderField("") + _ fmt.Stringer = RiskAssessmentOrderField("") + _ encoding.TextMarshaler = RiskAssessmentOrderField("") + _ encoding.TextUnmarshaler = (*RiskAssessmentOrderField)(nil) +) + +func RiskAssessmentOrderFields() []RiskAssessmentOrderField { + return []RiskAssessmentOrderField{ + RiskAssessmentOrderFieldCreatedAt, + RiskAssessmentOrderFieldName, + } +} + +func (v RiskAssessmentOrderField) IsValid() bool { + switch v { + case + RiskAssessmentOrderFieldCreatedAt, + RiskAssessmentOrderFieldName: + return true + } + + return false +} + +func (v RiskAssessmentOrderField) String() string { + return string(v) +} + +func (v RiskAssessmentOrderField) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *RiskAssessmentOrderField) UnmarshalText(text []byte) error { + val := RiskAssessmentOrderField(text) + if !val.IsValid() { + return fmt.Errorf("invalid RiskAssessmentOrderField value: %q", string(text)) + } + + *v = val + + return nil +} + func (p RiskAssessmentOrderField) Column() string { return string(p) } - -func (p RiskAssessmentOrderField) String() string { - return string(p) -} - -func (p RiskAssessmentOrderField) MarshalText() ([]byte, error) { - return []byte(p.String()), nil -} - -func (p *RiskAssessmentOrderField) UnmarshalText(text []byte) error { - *p = RiskAssessmentOrderField(text) - return nil -} diff --git a/pkg/coredata/risk_assessment_process_order_field.go b/pkg/coredata/risk_assessment_process_order_field.go index f25278be1..f3d032541 100644 --- a/pkg/coredata/risk_assessment_process_order_field.go +++ b/pkg/coredata/risk_assessment_process_order_field.go @@ -14,6 +14,13 @@ package coredata +import ( + "encoding" + "fmt" + + "go.probo.inc/probo/pkg/page" +) + type RiskAssessmentProcessOrderField string const ( @@ -21,14 +28,48 @@ const ( RiskAssessmentProcessOrderFieldName RiskAssessmentProcessOrderField = "NAME" ) -func (p RiskAssessmentProcessOrderField) Column() string { return string(p) } -func (p RiskAssessmentProcessOrderField) String() string { return string(p) } +var ( + _ page.OrderField = RiskAssessmentProcessOrderField("") + _ fmt.Stringer = RiskAssessmentProcessOrderField("") + _ encoding.TextMarshaler = RiskAssessmentProcessOrderField("") + _ encoding.TextUnmarshaler = (*RiskAssessmentProcessOrderField)(nil) +) -func (p RiskAssessmentProcessOrderField) MarshalText() ([]byte, error) { - return []byte(p.String()), nil +func RiskAssessmentProcessOrderFields() []RiskAssessmentProcessOrderField { + return []RiskAssessmentProcessOrderField{ + RiskAssessmentProcessOrderFieldCreatedAt, + RiskAssessmentProcessOrderFieldName, + } } -func (p *RiskAssessmentProcessOrderField) UnmarshalText(text []byte) error { - *p = RiskAssessmentProcessOrderField(text) +func (v RiskAssessmentProcessOrderField) IsValid() bool { + switch v { + case + RiskAssessmentProcessOrderFieldCreatedAt, + RiskAssessmentProcessOrderFieldName: + return true + } + + return false +} + +func (v RiskAssessmentProcessOrderField) String() string { + return string(v) +} + +func (v RiskAssessmentProcessOrderField) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *RiskAssessmentProcessOrderField) UnmarshalText(text []byte) error { + val := RiskAssessmentProcessOrderField(text) + if !val.IsValid() { + return fmt.Errorf("invalid RiskAssessmentProcessOrderField value: %q", string(text)) + } + + *v = val + return nil } + +func (p RiskAssessmentProcessOrderField) Column() string { return string(p) } diff --git a/pkg/coredata/risk_assessment_scenario_order_field.go b/pkg/coredata/risk_assessment_scenario_order_field.go index 8dc26c403..6c1912f80 100644 --- a/pkg/coredata/risk_assessment_scenario_order_field.go +++ b/pkg/coredata/risk_assessment_scenario_order_field.go @@ -14,6 +14,13 @@ package coredata +import ( + "encoding" + "fmt" + + "go.probo.inc/probo/pkg/page" +) + type RiskAssessmentScenarioOrderField string const ( @@ -21,14 +28,48 @@ const ( RiskAssessmentScenarioOrderFieldName RiskAssessmentScenarioOrderField = "NAME" ) -func (p RiskAssessmentScenarioOrderField) Column() string { return string(p) } -func (p RiskAssessmentScenarioOrderField) String() string { return string(p) } +var ( + _ page.OrderField = RiskAssessmentScenarioOrderField("") + _ fmt.Stringer = RiskAssessmentScenarioOrderField("") + _ encoding.TextMarshaler = RiskAssessmentScenarioOrderField("") + _ encoding.TextUnmarshaler = (*RiskAssessmentScenarioOrderField)(nil) +) -func (p RiskAssessmentScenarioOrderField) MarshalText() ([]byte, error) { - return []byte(p.String()), nil +func RiskAssessmentScenarioOrderFields() []RiskAssessmentScenarioOrderField { + return []RiskAssessmentScenarioOrderField{ + RiskAssessmentScenarioOrderFieldCreatedAt, + RiskAssessmentScenarioOrderFieldName, + } } -func (p *RiskAssessmentScenarioOrderField) UnmarshalText(text []byte) error { - *p = RiskAssessmentScenarioOrderField(text) +func (v RiskAssessmentScenarioOrderField) IsValid() bool { + switch v { + case + RiskAssessmentScenarioOrderFieldCreatedAt, + RiskAssessmentScenarioOrderFieldName: + return true + } + + return false +} + +func (v RiskAssessmentScenarioOrderField) String() string { + return string(v) +} + +func (v RiskAssessmentScenarioOrderField) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *RiskAssessmentScenarioOrderField) UnmarshalText(text []byte) error { + val := RiskAssessmentScenarioOrderField(text) + if !val.IsValid() { + return fmt.Errorf("invalid RiskAssessmentScenarioOrderField value: %q", string(text)) + } + + *v = val + return nil } + +func (p RiskAssessmentScenarioOrderField) Column() string { return string(p) } diff --git a/pkg/coredata/risk_assessment_scope_order_field.go b/pkg/coredata/risk_assessment_scope_order_field.go index 1aa41a2e7..8d36bf943 100644 --- a/pkg/coredata/risk_assessment_scope_order_field.go +++ b/pkg/coredata/risk_assessment_scope_order_field.go @@ -14,6 +14,13 @@ package coredata +import ( + "encoding" + "fmt" + + "go.probo.inc/probo/pkg/page" +) + type RiskAssessmentScopeOrderField string const ( @@ -21,14 +28,48 @@ const ( RiskAssessmentScopeOrderFieldName RiskAssessmentScopeOrderField = "NAME" ) -func (p RiskAssessmentScopeOrderField) Column() string { return string(p) } -func (p RiskAssessmentScopeOrderField) String() string { return string(p) } +var ( + _ page.OrderField = RiskAssessmentScopeOrderField("") + _ fmt.Stringer = RiskAssessmentScopeOrderField("") + _ encoding.TextMarshaler = RiskAssessmentScopeOrderField("") + _ encoding.TextUnmarshaler = (*RiskAssessmentScopeOrderField)(nil) +) -func (p RiskAssessmentScopeOrderField) MarshalText() ([]byte, error) { - return []byte(p.String()), nil +func RiskAssessmentScopeOrderFields() []RiskAssessmentScopeOrderField { + return []RiskAssessmentScopeOrderField{ + RiskAssessmentScopeOrderFieldCreatedAt, + RiskAssessmentScopeOrderFieldName, + } } -func (p *RiskAssessmentScopeOrderField) UnmarshalText(text []byte) error { - *p = RiskAssessmentScopeOrderField(text) +func (v RiskAssessmentScopeOrderField) IsValid() bool { + switch v { + case + RiskAssessmentScopeOrderFieldCreatedAt, + RiskAssessmentScopeOrderFieldName: + return true + } + + return false +} + +func (v RiskAssessmentScopeOrderField) String() string { + return string(v) +} + +func (v RiskAssessmentScopeOrderField) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *RiskAssessmentScopeOrderField) UnmarshalText(text []byte) error { + val := RiskAssessmentScopeOrderField(text) + if !val.IsValid() { + return fmt.Errorf("invalid RiskAssessmentScopeOrderField value: %q", string(text)) + } + + *v = val + return nil } + +func (p RiskAssessmentScopeOrderField) Column() string { return string(p) } diff --git a/pkg/coredata/risk_assessment_threat_order_field.go b/pkg/coredata/risk_assessment_threat_order_field.go index 0b41fbbe7..b56a07ecb 100644 --- a/pkg/coredata/risk_assessment_threat_order_field.go +++ b/pkg/coredata/risk_assessment_threat_order_field.go @@ -14,6 +14,13 @@ package coredata +import ( + "encoding" + "fmt" + + "go.probo.inc/probo/pkg/page" +) + type RiskAssessmentThreatOrderField string const ( @@ -21,14 +28,48 @@ const ( RiskAssessmentThreatOrderFieldName RiskAssessmentThreatOrderField = "NAME" ) -func (p RiskAssessmentThreatOrderField) Column() string { return string(p) } -func (p RiskAssessmentThreatOrderField) String() string { return string(p) } +var ( + _ page.OrderField = RiskAssessmentThreatOrderField("") + _ fmt.Stringer = RiskAssessmentThreatOrderField("") + _ encoding.TextMarshaler = RiskAssessmentThreatOrderField("") + _ encoding.TextUnmarshaler = (*RiskAssessmentThreatOrderField)(nil) +) -func (p RiskAssessmentThreatOrderField) MarshalText() ([]byte, error) { - return []byte(p.String()), nil +func RiskAssessmentThreatOrderFields() []RiskAssessmentThreatOrderField { + return []RiskAssessmentThreatOrderField{ + RiskAssessmentThreatOrderFieldCreatedAt, + RiskAssessmentThreatOrderFieldName, + } } -func (p *RiskAssessmentThreatOrderField) UnmarshalText(text []byte) error { - *p = RiskAssessmentThreatOrderField(text) +func (v RiskAssessmentThreatOrderField) IsValid() bool { + switch v { + case + RiskAssessmentThreatOrderFieldCreatedAt, + RiskAssessmentThreatOrderFieldName: + return true + } + + return false +} + +func (v RiskAssessmentThreatOrderField) String() string { + return string(v) +} + +func (v RiskAssessmentThreatOrderField) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *RiskAssessmentThreatOrderField) UnmarshalText(text []byte) error { + val := RiskAssessmentThreatOrderField(text) + if !val.IsValid() { + return fmt.Errorf("invalid RiskAssessmentThreatOrderField value: %q", string(text)) + } + + *v = val + return nil } + +func (p RiskAssessmentThreatOrderField) Column() string { return string(p) } diff --git a/pkg/coredata/risk_order_field.go b/pkg/coredata/risk_order_field.go index cdc95162d..88d76c445 100644 --- a/pkg/coredata/risk_order_field.go +++ b/pkg/coredata/risk_order_field.go @@ -14,6 +14,13 @@ package coredata +import ( + "encoding" + "fmt" + + "go.probo.inc/probo/pkg/page" +) + type ( RiskOrderField string ) @@ -29,19 +36,62 @@ const ( RiskOrderFieldOwnerFullName RiskOrderField = "OWNER_FULL_NAME" ) +var ( + _ page.OrderField = RiskOrderField("") + _ fmt.Stringer = RiskOrderField("") + _ encoding.TextMarshaler = RiskOrderField("") + _ encoding.TextUnmarshaler = (*RiskOrderField)(nil) +) + +func RiskOrderFields() []RiskOrderField { + return []RiskOrderField{ + RiskOrderFieldCreatedAt, + RiskOrderFieldUpdatedAt, + RiskOrderFieldName, + RiskOrderFieldCategory, + RiskOrderFieldTreatment, + RiskOrderFieldInherentRiskScore, + RiskOrderFieldResidualRiskScore, + RiskOrderFieldOwnerFullName, + } +} + +func (v RiskOrderField) IsValid() bool { + switch v { + case + RiskOrderFieldCreatedAt, + RiskOrderFieldUpdatedAt, + RiskOrderFieldName, + RiskOrderFieldCategory, + RiskOrderFieldTreatment, + RiskOrderFieldInherentRiskScore, + RiskOrderFieldResidualRiskScore, + RiskOrderFieldOwnerFullName: + return true + } + + return false +} + +func (v RiskOrderField) String() string { + return string(v) +} + +func (v RiskOrderField) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *RiskOrderField) UnmarshalText(text []byte) error { + val := RiskOrderField(text) + if !val.IsValid() { + return fmt.Errorf("invalid RiskOrderField value: %q", string(text)) + } + + *v = val + + return nil +} + func (p RiskOrderField) Column() string { return string(p) } - -func (p RiskOrderField) String() string { - return string(p) -} - -func (p RiskOrderField) MarshalText() ([]byte, error) { - return []byte(p.String()), nil -} - -func (p *RiskOrderField) UnmarshalText(text []byte) error { - *p = RiskOrderField(text) - return nil -} diff --git a/pkg/coredata/risk_treatment.go b/pkg/coredata/risk_treatment.go index 590aeb749..6dc8e9a39 100644 --- a/pkg/coredata/risk_treatment.go +++ b/pkg/coredata/risk_treatment.go @@ -15,7 +15,7 @@ package coredata import ( - "database/sql/driver" + "encoding" "fmt" ) @@ -30,6 +30,12 @@ const ( RiskTreatmentTransferred RiskTreatment = "TRANSFERRED" ) +var ( + _ fmt.Stringer = RiskTreatment("") + _ encoding.TextMarshaler = RiskTreatment("") + _ encoding.TextUnmarshaler = (*RiskTreatment)(nil) +) + func RiskTreatments() []RiskTreatment { return []RiskTreatment{ RiskTreatmentMitigated, @@ -39,55 +45,34 @@ func RiskTreatments() []RiskTreatment { } } -func (rt RiskTreatment) MarshalText() ([]byte, error) { - return []byte(rt.String()), nil +func (v RiskTreatment) IsValid() bool { + switch v { + case + RiskTreatmentMitigated, + RiskTreatmentAccepted, + RiskTreatmentAvoided, + RiskTreatmentTransferred: + return true + } + + return false } -func (rt *RiskTreatment) UnmarshalText(data []byte) error { - val := string(data) +func (v RiskTreatment) String() string { + return string(v) +} - switch val { - case RiskTreatmentMitigated.String(): - *rt = RiskTreatmentMitigated - case RiskTreatmentAccepted.String(): - *rt = RiskTreatmentAccepted - case RiskTreatmentAvoided.String(): - *rt = RiskTreatmentAvoided - case RiskTreatmentTransferred.String(): - *rt = RiskTreatmentTransferred - default: - return fmt.Errorf("invalid RiskTreatment value: %q", val) +func (v RiskTreatment) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *RiskTreatment) UnmarshalText(text []byte) error { + val := RiskTreatment(text) + if !val.IsValid() { + return fmt.Errorf("invalid RiskTreatment value: %q", string(text)) } + *v = val + return nil } - -func (rt RiskTreatment) String() string { - var val string - - switch rt { - case RiskTreatmentMitigated: - val = "MITIGATED" - case RiskTreatmentAccepted: - val = "ACCEPTED" - case RiskTreatmentAvoided: - val = "AVOIDED" - case RiskTreatmentTransferred: - val = "TRANSFERRED" - } - - return val -} - -func (rt *RiskTreatment) Scan(value any) error { - val, ok := value.(string) - if !ok { - return fmt.Errorf("invalid scan source for RiskTreatment, expected string got %T", value) - } - - return rt.UnmarshalText([]byte(val)) -} - -func (rt RiskTreatment) Value() (driver.Value, error) { - return rt.String(), nil -} diff --git a/pkg/coredata/saml_configuration_order_field.go b/pkg/coredata/saml_configuration_order_field.go index 380b0197a..4dea85b94 100644 --- a/pkg/coredata/saml_configuration_order_field.go +++ b/pkg/coredata/saml_configuration_order_field.go @@ -14,6 +14,13 @@ package coredata +import ( + "encoding" + "fmt" + + "go.probo.inc/probo/pkg/page" +) + type ( SAMLConfigurationOrderField string ) @@ -22,19 +29,48 @@ const ( SAMLConfigurationOrderFieldCreatedAt SAMLConfigurationOrderField = "CREATED_AT" ) +var ( + _ page.OrderField = SAMLConfigurationOrderField("") + _ fmt.Stringer = SAMLConfigurationOrderField("") + _ encoding.TextMarshaler = SAMLConfigurationOrderField("") + _ encoding.TextUnmarshaler = (*SAMLConfigurationOrderField)(nil) +) + +func SAMLConfigurationOrderFields() []SAMLConfigurationOrderField { + return []SAMLConfigurationOrderField{ + SAMLConfigurationOrderFieldCreatedAt, + } +} + +func (v SAMLConfigurationOrderField) IsValid() bool { + switch v { + case + SAMLConfigurationOrderFieldCreatedAt: + return true + } + + return false +} + +func (v SAMLConfigurationOrderField) String() string { + return string(v) +} + +func (v SAMLConfigurationOrderField) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *SAMLConfigurationOrderField) UnmarshalText(text []byte) error { + val := SAMLConfigurationOrderField(text) + if !val.IsValid() { + return fmt.Errorf("invalid SAMLConfigurationOrderField value: %q", string(text)) + } + + *v = val + + return nil +} + func (p SAMLConfigurationOrderField) Column() string { return string(p) } - -func (p SAMLConfigurationOrderField) String() string { - return string(p) -} - -func (p SAMLConfigurationOrderField) MarshalText() ([]byte, error) { - return []byte(p.String()), nil -} - -func (p *SAMLConfigurationOrderField) UnmarshalText(text []byte) error { - *p = SAMLConfigurationOrderField(text) - return nil -} diff --git a/pkg/coredata/saml_enforcement_policy.go b/pkg/coredata/saml_enforcement_policy.go index b5cd17ed2..7ddbae2a3 100644 --- a/pkg/coredata/saml_enforcement_policy.go +++ b/pkg/coredata/saml_enforcement_policy.go @@ -15,7 +15,7 @@ package coredata import ( - "database/sql/driver" + "encoding" "fmt" ) @@ -27,36 +27,47 @@ const ( SAMLEnforcementPolicyRequired SAMLEnforcementPolicy = "REQUIRED" ) -func (sep SAMLEnforcementPolicy) String() string { - return string(sep) +var ( + _ fmt.Stringer = SAMLEnforcementPolicy("") + _ encoding.TextMarshaler = SAMLEnforcementPolicy("") + _ encoding.TextUnmarshaler = (*SAMLEnforcementPolicy)(nil) +) + +func SAMLEnforcementPolicies() []SAMLEnforcementPolicy { + return []SAMLEnforcementPolicy{ + SAMLEnforcementPolicyOff, + SAMLEnforcementPolicyOptional, + SAMLEnforcementPolicyRequired, + } } -func (sep *SAMLEnforcementPolicy) Scan(value any) error { - var s string - - switch v := value.(type) { - case string: - s = v - case []byte: - s = string(v) - default: - return fmt.Errorf("unsupported type for SAMLEnforcementPolicy: %T", value) +func (v SAMLEnforcementPolicy) IsValid() bool { + switch v { + case + SAMLEnforcementPolicyOff, + SAMLEnforcementPolicyOptional, + SAMLEnforcementPolicyRequired: + return true } - switch s { - case "OFF": - *sep = SAMLEnforcementPolicyOff - case "OPTIONAL": - *sep = SAMLEnforcementPolicyOptional - case "REQUIRED": - *sep = SAMLEnforcementPolicyRequired - default: - return fmt.Errorf("invalid SAMLEnforcementPolicy value: %q", s) + return false +} + +func (v SAMLEnforcementPolicy) String() string { + return string(v) +} + +func (v SAMLEnforcementPolicy) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *SAMLEnforcementPolicy) UnmarshalText(text []byte) error { + val := SAMLEnforcementPolicy(text) + if !val.IsValid() { + return fmt.Errorf("invalid SAMLEnforcementPolicy value: %q", string(text)) } + *v = val + return nil } - -func (sep SAMLEnforcementPolicy) Value() (driver.Value, error) { - return sep.String(), nil -} diff --git a/pkg/coredata/scim_bridge_order_field.go b/pkg/coredata/scim_bridge_order_field.go index 451f7f479..4a047a85a 100644 --- a/pkg/coredata/scim_bridge_order_field.go +++ b/pkg/coredata/scim_bridge_order_field.go @@ -14,6 +14,13 @@ package coredata +import ( + "encoding" + "fmt" + + "go.probo.inc/probo/pkg/page" +) + type ( SCIMBridgeOrderField string ) @@ -22,19 +29,48 @@ const ( SCIMBridgeOrderFieldCreatedAt SCIMBridgeOrderField = "CREATED_AT" ) +var ( + _ page.OrderField = SCIMBridgeOrderField("") + _ fmt.Stringer = SCIMBridgeOrderField("") + _ encoding.TextMarshaler = SCIMBridgeOrderField("") + _ encoding.TextUnmarshaler = (*SCIMBridgeOrderField)(nil) +) + +func SCIMBridgeOrderFields() []SCIMBridgeOrderField { + return []SCIMBridgeOrderField{ + SCIMBridgeOrderFieldCreatedAt, + } +} + +func (v SCIMBridgeOrderField) IsValid() bool { + switch v { + case + SCIMBridgeOrderFieldCreatedAt: + return true + } + + return false +} + +func (v SCIMBridgeOrderField) String() string { + return string(v) +} + +func (v SCIMBridgeOrderField) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *SCIMBridgeOrderField) UnmarshalText(text []byte) error { + val := SCIMBridgeOrderField(text) + if !val.IsValid() { + return fmt.Errorf("invalid SCIMBridgeOrderField value: %q", string(text)) + } + + *v = val + + return nil +} + func (p SCIMBridgeOrderField) Column() string { return string(p) } - -func (p SCIMBridgeOrderField) String() string { - return string(p) -} - -func (p SCIMBridgeOrderField) MarshalText() ([]byte, error) { - return []byte(p.String()), nil -} - -func (p *SCIMBridgeOrderField) UnmarshalText(text []byte) error { - *p = SCIMBridgeOrderField(text) - return nil -} diff --git a/pkg/coredata/scim_bridge_state.go b/pkg/coredata/scim_bridge_state.go index 3608f396e..ab417012f 100644 --- a/pkg/coredata/scim_bridge_state.go +++ b/pkg/coredata/scim_bridge_state.go @@ -15,7 +15,7 @@ package coredata import ( - "database/sql/driver" + "encoding" "fmt" ) @@ -29,40 +29,51 @@ const ( SCIMBridgeStateDisabled SCIMBridgeState = "DISABLED" ) -func (s SCIMBridgeState) String() string { - return string(s) +var ( + _ fmt.Stringer = SCIMBridgeState("") + _ encoding.TextMarshaler = SCIMBridgeState("") + _ encoding.TextUnmarshaler = (*SCIMBridgeState)(nil) +) + +func SCIMBridgeStates() []SCIMBridgeState { + return []SCIMBridgeState{ + SCIMBridgeStatePending, + SCIMBridgeStateActive, + SCIMBridgeStateSyncing, + SCIMBridgeStateFailed, + SCIMBridgeStateDisabled, + } } -func (s *SCIMBridgeState) Scan(value any) error { - var str string - - switch v := value.(type) { - case string: - str = v - case []byte: - str = string(v) - default: - return fmt.Errorf("unsupported type for SCIMBridgeState: %T", value) +func (v SCIMBridgeState) IsValid() bool { + switch v { + case + SCIMBridgeStatePending, + SCIMBridgeStateActive, + SCIMBridgeStateSyncing, + SCIMBridgeStateFailed, + SCIMBridgeStateDisabled: + return true } - switch str { - case "PENDING": - *s = SCIMBridgeStatePending - case "ACTIVE": - *s = SCIMBridgeStateActive - case "SYNCING": - *s = SCIMBridgeStateSyncing - case "FAILED": - *s = SCIMBridgeStateFailed - case "DISABLED": - *s = SCIMBridgeStateDisabled - default: - return fmt.Errorf("invalid SCIMBridgeState value: %q", str) + return false +} + +func (v SCIMBridgeState) String() string { + return string(v) +} + +func (v SCIMBridgeState) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *SCIMBridgeState) UnmarshalText(text []byte) error { + val := SCIMBridgeState(text) + if !val.IsValid() { + return fmt.Errorf("invalid SCIMBridgeState value: %q", string(text)) } + *v = val + return nil } - -func (s SCIMBridgeState) Value() (driver.Value, error) { - return s.String(), nil -} diff --git a/pkg/coredata/scim_bridge_type.go b/pkg/coredata/scim_bridge_type.go index 11d17530a..47b870855 100644 --- a/pkg/coredata/scim_bridge_type.go +++ b/pkg/coredata/scim_bridge_type.go @@ -15,7 +15,7 @@ package coredata import ( - "database/sql/driver" + "encoding" "fmt" ) @@ -26,34 +26,45 @@ const ( SCIMBridgeTypeMicrosoft365 SCIMBridgeType = "MICROSOFT_365" ) -func (t SCIMBridgeType) String() string { - return string(t) +var ( + _ fmt.Stringer = SCIMBridgeType("") + _ encoding.TextMarshaler = SCIMBridgeType("") + _ encoding.TextUnmarshaler = (*SCIMBridgeType)(nil) +) + +func SCIMBridgeTypes() []SCIMBridgeType { + return []SCIMBridgeType{ + SCIMBridgeTypeGoogleWorkspace, + SCIMBridgeTypeMicrosoft365, + } } -func (t *SCIMBridgeType) Scan(value any) error { - var str string - - switch v := value.(type) { - case string: - str = v - case []byte: - str = string(v) - default: - return fmt.Errorf("unsupported type for SCIMBridgeType: %T", value) +func (v SCIMBridgeType) IsValid() bool { + switch v { + case + SCIMBridgeTypeGoogleWorkspace, + SCIMBridgeTypeMicrosoft365: + return true } - switch str { - case "GOOGLE_WORKSPACE": - *t = SCIMBridgeTypeGoogleWorkspace - case "MICROSOFT_365": - *t = SCIMBridgeTypeMicrosoft365 - default: - return fmt.Errorf("invalid SCIMBridgeType value: %q", str) + return false +} + +func (v SCIMBridgeType) String() string { + return string(v) +} + +func (v SCIMBridgeType) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *SCIMBridgeType) UnmarshalText(text []byte) error { + val := SCIMBridgeType(text) + if !val.IsValid() { + return fmt.Errorf("invalid SCIMBridgeType value: %q", string(text)) } + *v = val + return nil } - -func (t SCIMBridgeType) Value() (driver.Value, error) { - return t.String(), nil -} diff --git a/pkg/coredata/scim_configuration_order_field.go b/pkg/coredata/scim_configuration_order_field.go index a1622b091..08d9e0b2c 100644 --- a/pkg/coredata/scim_configuration_order_field.go +++ b/pkg/coredata/scim_configuration_order_field.go @@ -14,6 +14,13 @@ package coredata +import ( + "encoding" + "fmt" + + "go.probo.inc/probo/pkg/page" +) + type ( SCIMConfigurationOrderField string ) @@ -22,19 +29,48 @@ const ( SCIMConfigurationOrderFieldCreatedAt SCIMConfigurationOrderField = "CREATED_AT" ) +var ( + _ page.OrderField = SCIMConfigurationOrderField("") + _ fmt.Stringer = SCIMConfigurationOrderField("") + _ encoding.TextMarshaler = SCIMConfigurationOrderField("") + _ encoding.TextUnmarshaler = (*SCIMConfigurationOrderField)(nil) +) + +func SCIMConfigurationOrderFields() []SCIMConfigurationOrderField { + return []SCIMConfigurationOrderField{ + SCIMConfigurationOrderFieldCreatedAt, + } +} + +func (v SCIMConfigurationOrderField) IsValid() bool { + switch v { + case + SCIMConfigurationOrderFieldCreatedAt: + return true + } + + return false +} + +func (v SCIMConfigurationOrderField) String() string { + return string(v) +} + +func (v SCIMConfigurationOrderField) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *SCIMConfigurationOrderField) UnmarshalText(text []byte) error { + val := SCIMConfigurationOrderField(text) + if !val.IsValid() { + return fmt.Errorf("invalid SCIMConfigurationOrderField value: %q", string(text)) + } + + *v = val + + return nil +} + func (p SCIMConfigurationOrderField) Column() string { return string(p) } - -func (p SCIMConfigurationOrderField) String() string { - return string(p) -} - -func (p SCIMConfigurationOrderField) MarshalText() ([]byte, error) { - return []byte(p.String()), nil -} - -func (p *SCIMConfigurationOrderField) UnmarshalText(text []byte) error { - *p = SCIMConfigurationOrderField(text) - return nil -} diff --git a/pkg/coredata/scim_event_order_field.go b/pkg/coredata/scim_event_order_field.go index fde6fdb43..be1622098 100644 --- a/pkg/coredata/scim_event_order_field.go +++ b/pkg/coredata/scim_event_order_field.go @@ -14,6 +14,13 @@ package coredata +import ( + "encoding" + "fmt" + + "go.probo.inc/probo/pkg/page" +) + type ( SCIMEventOrderField string ) @@ -22,19 +29,48 @@ const ( SCIMEventOrderFieldCreatedAt SCIMEventOrderField = "CREATED_AT" ) +var ( + _ page.OrderField = SCIMEventOrderField("") + _ fmt.Stringer = SCIMEventOrderField("") + _ encoding.TextMarshaler = SCIMEventOrderField("") + _ encoding.TextUnmarshaler = (*SCIMEventOrderField)(nil) +) + +func SCIMEventOrderFields() []SCIMEventOrderField { + return []SCIMEventOrderField{ + SCIMEventOrderFieldCreatedAt, + } +} + +func (v SCIMEventOrderField) IsValid() bool { + switch v { + case + SCIMEventOrderFieldCreatedAt: + return true + } + + return false +} + +func (v SCIMEventOrderField) String() string { + return string(v) +} + +func (v SCIMEventOrderField) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *SCIMEventOrderField) UnmarshalText(text []byte) error { + val := SCIMEventOrderField(text) + if !val.IsValid() { + return fmt.Errorf("invalid SCIMEventOrderField value: %q", string(text)) + } + + *v = val + + return nil +} + func (p SCIMEventOrderField) Column() string { return string(p) } - -func (p SCIMEventOrderField) String() string { - return string(p) -} - -func (p SCIMEventOrderField) MarshalText() ([]byte, error) { - return []byte(p.String()), nil -} - -func (p *SCIMEventOrderField) UnmarshalText(text []byte) error { - *p = SCIMEventOrderField(text) - return nil -} diff --git a/pkg/coredata/search_engine_indexing.go b/pkg/coredata/search_engine_indexing.go index 85e341af8..92678a574 100644 --- a/pkg/coredata/search_engine_indexing.go +++ b/pkg/coredata/search_engine_indexing.go @@ -15,7 +15,7 @@ package coredata import ( - "database/sql/driver" + "encoding" "fmt" ) @@ -26,56 +26,45 @@ const ( SearchEngineIndexingNotIndexable SearchEngineIndexing = "NOT_INDEXABLE" ) -func (s SearchEngineIndexing) String() string { - return string(s) +var ( + _ fmt.Stringer = SearchEngineIndexing("") + _ encoding.TextMarshaler = SearchEngineIndexing("") + _ encoding.TextUnmarshaler = (*SearchEngineIndexing)(nil) +) + +func SearchEngineIndexings() []SearchEngineIndexing { + return []SearchEngineIndexing{ + SearchEngineIndexingIndexable, + SearchEngineIndexingNotIndexable, + } } -func (s SearchEngineIndexing) IsValid() bool { - switch s { - case SearchEngineIndexingIndexable, SearchEngineIndexingNotIndexable: +func (v SearchEngineIndexing) IsValid() bool { + switch v { + case + SearchEngineIndexingIndexable, + SearchEngineIndexingNotIndexable: return true } return false } -func (s *SearchEngineIndexing) UnmarshalText(text []byte) error { - *s = SearchEngineIndexing(text) - if !s.IsValid() { - return fmt.Errorf("%s is not a valid SearchEngineIndexing", string(text)) +func (v SearchEngineIndexing) String() string { + return string(v) +} + +func (v SearchEngineIndexing) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *SearchEngineIndexing) UnmarshalText(text []byte) error { + val := SearchEngineIndexing(text) + if !val.IsValid() { + return fmt.Errorf("invalid SearchEngineIndexing value: %q", string(text)) } + *v = val + return nil } - -func (s SearchEngineIndexing) MarshalText() ([]byte, error) { - return []byte(s.String()), nil -} - -func (s *SearchEngineIndexing) Scan(value any) error { - var str string - - switch v := value.(type) { - case string: - str = v - case []byte: - str = string(v) - default: - return fmt.Errorf("unsupported type for SearchEngineIndexing: %T", value) - } - - switch str { - case "INDEXABLE": - *s = SearchEngineIndexingIndexable - case "NOT_INDEXABLE": - *s = SearchEngineIndexingNotIndexable - default: - return fmt.Errorf("invalid SearchEngineIndexing value: %q", str) - } - - return nil -} - -func (s SearchEngineIndexing) Value() (driver.Value, error) { - return s.String(), nil -} diff --git a/pkg/coredata/session.go b/pkg/coredata/session.go index 275476a66..e12e8df17 100644 --- a/pkg/coredata/session.go +++ b/pkg/coredata/session.go @@ -16,6 +16,7 @@ package coredata import ( "context" + "encoding" "errors" "fmt" "maps" @@ -60,6 +61,53 @@ const ( AuthMethodOIDC AuthMethod = "OIDC" ) +var ( + _ fmt.Stringer = AuthMethod("") + _ encoding.TextMarshaler = AuthMethod("") + _ encoding.TextUnmarshaler = (*AuthMethod)(nil) +) + +func AuthMethods() []AuthMethod { + return []AuthMethod{ + AuthMethodMagicLink, + AuthMethodPassword, + AuthMethodSAML, + AuthMethodOIDC, + } +} + +func (v AuthMethod) IsValid() bool { + switch v { + case + AuthMethodMagicLink, + AuthMethodPassword, + AuthMethodSAML, + AuthMethodOIDC: + return true + } + + return false +} + +func (v AuthMethod) String() string { + return string(v) +} + +func (v AuthMethod) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *AuthMethod) UnmarshalText(text []byte) error { + val := AuthMethod(text) + if !val.IsValid() { + return fmt.Errorf("invalid AuthMethod value: %q", string(text)) + } + + *v = val + + return nil +} + func NewRootSession(identityID gid.GID, method AuthMethod, duration time.Duration) *Session { now := time.Now() diff --git a/pkg/coredata/session_order_field.go b/pkg/coredata/session_order_field.go index 20b8d5f84..ad9f0f761 100644 --- a/pkg/coredata/session_order_field.go +++ b/pkg/coredata/session_order_field.go @@ -14,6 +14,13 @@ package coredata +import ( + "encoding" + "fmt" + + "go.probo.inc/probo/pkg/page" +) + type ( SessionOrderField string ) @@ -24,6 +31,52 @@ const ( SessionOrderFieldUpdatedAt SessionOrderField = "UPDATED_AT" ) +var ( + _ page.OrderField = SessionOrderField("") + _ fmt.Stringer = SessionOrderField("") + _ encoding.TextMarshaler = SessionOrderField("") + _ encoding.TextUnmarshaler = (*SessionOrderField)(nil) +) + +func SessionOrderFields() []SessionOrderField { + return []SessionOrderField{ + SessionOrderFieldCreatedAt, + SessionOrderFieldExpiredAt, + SessionOrderFieldUpdatedAt, + } +} + +func (v SessionOrderField) IsValid() bool { + switch v { + case + SessionOrderFieldCreatedAt, + SessionOrderFieldExpiredAt, + SessionOrderFieldUpdatedAt: + return true + } + + return false +} + +func (v SessionOrderField) String() string { + return string(v) +} + +func (v SessionOrderField) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *SessionOrderField) UnmarshalText(text []byte) error { + val := SessionOrderField(text) + if !val.IsValid() { + return fmt.Errorf("invalid SessionOrderField value: %q", string(text)) + } + + *v = val + + return nil +} + func (p SessionOrderField) Column() string { switch p { case SessionOrderFieldCreatedAt: @@ -36,16 +89,3 @@ func (p SessionOrderField) Column() string { return string(p) } - -func (p SessionOrderField) String() string { - return string(p) -} - -func (p SessionOrderField) MarshalText() ([]byte, error) { - return []byte(p.String()), nil -} - -func (p *SessionOrderField) UnmarshalText(text []byte) error { - *p = SessionOrderField(text) - return nil -} diff --git a/pkg/coredata/slack_message_type.go b/pkg/coredata/slack_message_type.go index 2bea3b35f..936c70a39 100644 --- a/pkg/coredata/slack_message_type.go +++ b/pkg/coredata/slack_message_type.go @@ -15,7 +15,7 @@ package coredata import ( - "database/sql/driver" + "encoding" "fmt" ) @@ -26,34 +26,45 @@ const ( SlackMessageTypeWelcome SlackMessageType = "WELCOME" ) -func (smt SlackMessageType) String() string { - return string(smt) +var ( + _ fmt.Stringer = SlackMessageType("") + _ encoding.TextMarshaler = SlackMessageType("") + _ encoding.TextUnmarshaler = (*SlackMessageType)(nil) +) + +func SlackMessageTypes() []SlackMessageType { + return []SlackMessageType{ + SlackMessageTypeTrustCenterAccessRequest, + SlackMessageTypeWelcome, + } } -func (smt *SlackMessageType) Scan(value any) error { - var s string - - switch v := value.(type) { - case string: - s = v - case []byte: - s = string(v) - default: - return fmt.Errorf("unsupported type for SlackMessageType: %T", value) +func (v SlackMessageType) IsValid() bool { + switch v { + case + SlackMessageTypeTrustCenterAccessRequest, + SlackMessageTypeWelcome: + return true } - switch s { - case "TRUST_CENTER_ACCESS_REQUEST": - *smt = SlackMessageTypeTrustCenterAccessRequest - case "WELCOME": - *smt = SlackMessageTypeWelcome - default: - return fmt.Errorf("invalid SlackMessageType value: %q", s) + return false +} + +func (v SlackMessageType) String() string { + return string(v) +} + +func (v SlackMessageType) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *SlackMessageType) UnmarshalText(text []byte) error { + val := SlackMessageType(text) + if !val.IsValid() { + return fmt.Errorf("invalid SlackMessageType value: %q", string(text)) } + *v = val + return nil } - -func (smt SlackMessageType) Value() (driver.Value, error) { - return smt.String(), nil -} diff --git a/pkg/coredata/statement_of_applicability_order_field.go b/pkg/coredata/statement_of_applicability_order_field.go index a2b3625af..116f679df 100644 --- a/pkg/coredata/statement_of_applicability_order_field.go +++ b/pkg/coredata/statement_of_applicability_order_field.go @@ -15,7 +15,10 @@ package coredata import ( + "encoding" "fmt" + + "go.probo.inc/probo/pkg/page" ) type ( @@ -27,6 +30,50 @@ const ( StatementOfApplicabilityOrderFieldCreatedAt StatementOfApplicabilityOrderField = "CREATED_AT" ) +var ( + _ page.OrderField = StatementOfApplicabilityOrderField("") + _ fmt.Stringer = StatementOfApplicabilityOrderField("") + _ encoding.TextMarshaler = StatementOfApplicabilityOrderField("") + _ encoding.TextUnmarshaler = (*StatementOfApplicabilityOrderField)(nil) +) + +func StatementOfApplicabilityOrderFields() []StatementOfApplicabilityOrderField { + return []StatementOfApplicabilityOrderField{ + StatementOfApplicabilityOrderFieldName, + StatementOfApplicabilityOrderFieldCreatedAt, + } +} + +func (v StatementOfApplicabilityOrderField) IsValid() bool { + switch v { + case + StatementOfApplicabilityOrderFieldName, + StatementOfApplicabilityOrderFieldCreatedAt: + return true + } + + return false +} + +func (v StatementOfApplicabilityOrderField) String() string { + return string(v) +} + +func (v StatementOfApplicabilityOrderField) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *StatementOfApplicabilityOrderField) UnmarshalText(text []byte) error { + val := StatementOfApplicabilityOrderField(text) + if !val.IsValid() { + return fmt.Errorf("invalid StatementOfApplicabilityOrderField value: %q", string(text)) + } + + *v = val + + return nil +} + func (s StatementOfApplicabilityOrderField) Column() string { switch s { case StatementOfApplicabilityOrderFieldName: @@ -37,29 +84,3 @@ func (s StatementOfApplicabilityOrderField) Column() string { panic(fmt.Sprintf("unsupported order by: %s", s)) } - -func (s StatementOfApplicabilityOrderField) String() string { - return string(s) -} - -func (s StatementOfApplicabilityOrderField) IsValid() bool { - switch s { - case StatementOfApplicabilityOrderFieldName, StatementOfApplicabilityOrderFieldCreatedAt: - return true - } - - return false -} - -func (s StatementOfApplicabilityOrderField) MarshalText() ([]byte, error) { - return []byte(s.String()), nil -} - -func (s *StatementOfApplicabilityOrderField) UnmarshalText(text []byte) error { - *s = StatementOfApplicabilityOrderField(text) - if !s.IsValid() { - return fmt.Errorf("%s is not a valid StatementOfApplicabilityOrderField", string(text)) - } - - return nil -} diff --git a/pkg/coredata/task_order_field.go b/pkg/coredata/task_order_field.go index 11fb663b1..05e09283f 100644 --- a/pkg/coredata/task_order_field.go +++ b/pkg/coredata/task_order_field.go @@ -14,7 +14,12 @@ package coredata -import "fmt" +import ( + "encoding" + "fmt" + + "go.probo.inc/probo/pkg/page" +) type ( TaskOrderField string @@ -25,6 +30,50 @@ const ( TaskOrderFieldCreatedAt TaskOrderField = "CREATED_AT" ) +var ( + _ page.OrderField = TaskOrderField("") + _ fmt.Stringer = TaskOrderField("") + _ encoding.TextMarshaler = TaskOrderField("") + _ encoding.TextUnmarshaler = (*TaskOrderField)(nil) +) + +func TaskOrderFields() []TaskOrderField { + return []TaskOrderField{ + TaskOrderFieldPriorityRank, + TaskOrderFieldCreatedAt, + } +} + +func (v TaskOrderField) IsValid() bool { + switch v { + case + TaskOrderFieldPriorityRank, + TaskOrderFieldCreatedAt: + return true + } + + return false +} + +func (v TaskOrderField) String() string { + return string(v) +} + +func (v TaskOrderField) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *TaskOrderField) UnmarshalText(text []byte) error { + val := TaskOrderField(text) + if !val.IsValid() { + return fmt.Errorf("invalid TaskOrderField value: %q", string(text)) + } + + *v = val + + return nil +} + func (p TaskOrderField) Column() string { switch p { case TaskOrderFieldPriorityRank: @@ -35,29 +84,3 @@ func (p TaskOrderField) Column() string { panic(fmt.Sprintf("unsupported order by: %s", p)) } - -func (p TaskOrderField) IsValid() bool { - switch p { - case TaskOrderFieldPriorityRank, TaskOrderFieldCreatedAt: - return true - } - - return false -} - -func (p TaskOrderField) String() string { - return string(p) -} - -func (p TaskOrderField) MarshalText() ([]byte, error) { - return []byte(p.String()), nil -} - -func (p *TaskOrderField) UnmarshalText(text []byte) error { - *p = TaskOrderField(text) - if !p.IsValid() { - return fmt.Errorf("%s is not a valid TaskOrderField", string(text)) - } - - return nil -} diff --git a/pkg/coredata/task_priority.go b/pkg/coredata/task_priority.go index 7b44ec280..253709323 100644 --- a/pkg/coredata/task_priority.go +++ b/pkg/coredata/task_priority.go @@ -15,7 +15,7 @@ package coredata import ( - "database/sql/driver" + "encoding" "fmt" ) @@ -28,6 +28,12 @@ const ( TaskPriorityLow TaskPriority = "LOW" ) +var ( + _ fmt.Stringer = TaskPriority("") + _ encoding.TextMarshaler = TaskPriority("") + _ encoding.TextUnmarshaler = (*TaskPriority)(nil) +) + func TaskPriorities() []TaskPriority { return []TaskPriority{ TaskPriorityUrgent, @@ -37,38 +43,34 @@ func TaskPriorities() []TaskPriority { } } -func (tp TaskPriority) String() string { - return string(tp) +func (v TaskPriority) IsValid() bool { + switch v { + case + TaskPriorityUrgent, + TaskPriorityHigh, + TaskPriorityMedium, + TaskPriorityLow: + return true + } + + return false } -func (tp *TaskPriority) Scan(value any) error { - var s string +func (v TaskPriority) String() string { + return string(v) +} - switch v := value.(type) { - case string: - s = v - case []byte: - s = string(v) - default: - return fmt.Errorf("unsupported type for TaskPriority: %T", value) +func (v TaskPriority) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *TaskPriority) UnmarshalText(text []byte) error { + val := TaskPriority(text) + if !val.IsValid() { + return fmt.Errorf("invalid TaskPriority value: %q", string(text)) } - switch s { - case "URGENT": - *tp = TaskPriorityUrgent - case "HIGH": - *tp = TaskPriorityHigh - case "MEDIUM": - *tp = TaskPriorityMedium - case "LOW": - *tp = TaskPriorityLow - default: - return fmt.Errorf("invalid TaskPriority value: %q", s) - } + *v = val return nil } - -func (tp TaskPriority) Value() (driver.Value, error) { - return tp.String(), nil -} diff --git a/pkg/coredata/task_state.go b/pkg/coredata/task_state.go index b5e7004ef..41fc06d83 100644 --- a/pkg/coredata/task_state.go +++ b/pkg/coredata/task_state.go @@ -15,7 +15,7 @@ package coredata import ( - "database/sql/driver" + "encoding" "fmt" ) @@ -29,6 +29,12 @@ const ( TaskStateDone TaskState = "DONE" ) +var ( + _ fmt.Stringer = TaskState("") + _ encoding.TextMarshaler = TaskState("") + _ encoding.TextUnmarshaler = (*TaskState)(nil) +) + func TaskStates() []TaskState { return []TaskState{ TaskStateTodo, @@ -37,36 +43,33 @@ func TaskStates() []TaskState { } } -func (ts TaskState) MarshalText() ([]byte, error) { - return []byte(ts.String()), nil +func (v TaskState) IsValid() bool { + switch v { + case + TaskStateTodo, + TaskStateInProgress, + TaskStateDone: + return true + } + + return false } -func (ts *TaskState) UnmarshalText(data []byte) error { - val := TaskState(data) +func (v TaskState) String() string { + return string(v) +} - switch val { - case TaskStateTodo, TaskStateInProgress, TaskStateDone: - *ts = val - default: - return fmt.Errorf("invalid TaskState value: %q", val) +func (v TaskState) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *TaskState) UnmarshalText(text []byte) error { + val := TaskState(text) + if !val.IsValid() { + return fmt.Errorf("invalid TaskState value: %q", string(text)) } + *v = val + return nil } - -func (ts TaskState) String() string { - return string(ts) -} - -func (ts *TaskState) Scan(value any) error { - val, ok := value.(string) - if !ok { - return fmt.Errorf("invalid scan source for TaskState, expected string got %T", value) - } - - return ts.UnmarshalText([]byte(val)) -} - -func (ts TaskState) Value() (driver.Value, error) { - return ts.String(), nil -} diff --git a/pkg/coredata/third_party_business_associate_agreement_order_field.go b/pkg/coredata/third_party_business_associate_agreement_order_field.go index 77047cdce..ba91702dd 100644 --- a/pkg/coredata/third_party_business_associate_agreement_order_field.go +++ b/pkg/coredata/third_party_business_associate_agreement_order_field.go @@ -14,6 +14,13 @@ package coredata +import ( + "encoding" + "fmt" + + "go.probo.inc/probo/pkg/page" +) + type ( ThirdPartyBusinessAssociateAgreementOrderField string ) @@ -23,19 +30,50 @@ const ( ThirdPartyBusinessAssociateAgreementOrderFieldCreatedAt ThirdPartyBusinessAssociateAgreementOrderField = "CREATED_AT" ) +var ( + _ page.OrderField = ThirdPartyBusinessAssociateAgreementOrderField("") + _ fmt.Stringer = ThirdPartyBusinessAssociateAgreementOrderField("") + _ encoding.TextMarshaler = ThirdPartyBusinessAssociateAgreementOrderField("") + _ encoding.TextUnmarshaler = (*ThirdPartyBusinessAssociateAgreementOrderField)(nil) +) + +func ThirdPartyBusinessAssociateAgreementOrderFields() []ThirdPartyBusinessAssociateAgreementOrderField { + return []ThirdPartyBusinessAssociateAgreementOrderField{ + ThirdPartyBusinessAssociateAgreementOrderFieldValidFrom, + ThirdPartyBusinessAssociateAgreementOrderFieldCreatedAt, + } +} + +func (v ThirdPartyBusinessAssociateAgreementOrderField) IsValid() bool { + switch v { + case + ThirdPartyBusinessAssociateAgreementOrderFieldValidFrom, + ThirdPartyBusinessAssociateAgreementOrderFieldCreatedAt: + return true + } + + return false +} + +func (v ThirdPartyBusinessAssociateAgreementOrderField) String() string { + return string(v) +} + +func (v ThirdPartyBusinessAssociateAgreementOrderField) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *ThirdPartyBusinessAssociateAgreementOrderField) UnmarshalText(text []byte) error { + val := ThirdPartyBusinessAssociateAgreementOrderField(text) + if !val.IsValid() { + return fmt.Errorf("invalid ThirdPartyBusinessAssociateAgreementOrderField value: %q", string(text)) + } + + *v = val + + return nil +} + func (p ThirdPartyBusinessAssociateAgreementOrderField) Column() string { return string(p) } - -func (p ThirdPartyBusinessAssociateAgreementOrderField) String() string { - return string(p) -} - -func (p ThirdPartyBusinessAssociateAgreementOrderField) MarshalText() ([]byte, error) { - return []byte(p.String()), nil -} - -func (p *ThirdPartyBusinessAssociateAgreementOrderField) UnmarshalText(text []byte) error { - *p = ThirdPartyBusinessAssociateAgreementOrderField(text) - return nil -} diff --git a/pkg/coredata/third_party_category.go b/pkg/coredata/third_party_category.go index c75bda277..880b4ff09 100644 --- a/pkg/coredata/third_party_category.go +++ b/pkg/coredata/third_party_category.go @@ -15,8 +15,7 @@ package coredata import ( - "database/sql/driver" - "encoding/json" + "encoding" "fmt" ) @@ -47,6 +46,12 @@ const ( ThirdPartyCategoryVersionControl ThirdPartyCategory = "VERSION_CONTROL" ) +var ( + _ fmt.Stringer = ThirdPartyCategory("") + _ encoding.TextMarshaler = ThirdPartyCategory("") + _ encoding.TextUnmarshaler = (*ThirdPartyCategory)(nil) +) + func ThirdPartyCategories() []ThirdPartyCategory { return []ThirdPartyCategory{ ThirdPartyCategoryAnalytics, @@ -74,185 +79,52 @@ func ThirdPartyCategories() []ThirdPartyCategory { } } -func (i ThirdPartyCategory) String() string { - return string(i) +func (v ThirdPartyCategory) IsValid() bool { + switch v { + case + ThirdPartyCategoryAnalytics, + ThirdPartyCategoryCloudMonitoring, + ThirdPartyCategoryCloudProvider, + ThirdPartyCategoryCollaboration, + ThirdPartyCategoryCustomerSupport, + ThirdPartyCategoryDataStorageAndProcessing, + ThirdPartyCategoryDocumentManagement, + ThirdPartyCategoryEmployeeManagement, + ThirdPartyCategoryEngineering, + ThirdPartyCategoryFinance, + ThirdPartyCategoryIdentityProvider, + ThirdPartyCategoryIT, + ThirdPartyCategoryMarketing, + ThirdPartyCategoryOfficeOperations, + ThirdPartyCategoryOther, + ThirdPartyCategoryPasswordManagement, + ThirdPartyCategoryProductAndDesign, + ThirdPartyCategoryProfessionalServices, + ThirdPartyCategoryRecruiting, + ThirdPartyCategorySales, + ThirdPartyCategorySecurity, + ThirdPartyCategoryVersionControl: + return true + } + + return false } -func (i *ThirdPartyCategory) Scan(value any) error { - switch v := value.(type) { - case string: - switch v { - case "ANALYTICS": - *i = ThirdPartyCategoryAnalytics - case "CLOUD_MONITORING": - *i = ThirdPartyCategoryCloudMonitoring - case "CLOUD_PROVIDER": - *i = ThirdPartyCategoryCloudProvider - case "COLLABORATION": - *i = ThirdPartyCategoryCollaboration - case "CUSTOMER_SUPPORT": - *i = ThirdPartyCategoryCustomerSupport - case "DATA_STORAGE_AND_PROCESSING": - *i = ThirdPartyCategoryDataStorageAndProcessing - case "DOCUMENT_MANAGEMENT": - *i = ThirdPartyCategoryDocumentManagement - case "EMPLOYEE_MANAGEMENT": - *i = ThirdPartyCategoryEmployeeManagement - case "ENGINEERING": - *i = ThirdPartyCategoryEngineering - case "FINANCE": - *i = ThirdPartyCategoryFinance - case "IDENTITY_PROVIDER": - *i = ThirdPartyCategoryIdentityProvider - case "IT": - *i = ThirdPartyCategoryIT - case "MARKETING": - *i = ThirdPartyCategoryMarketing - case "OFFICE_OPERATIONS": - *i = ThirdPartyCategoryOfficeOperations - case "OTHER": - *i = ThirdPartyCategoryOther - case "PASSWORD_MANAGEMENT": - *i = ThirdPartyCategoryPasswordManagement - case "PRODUCT_AND_DESIGN": - *i = ThirdPartyCategoryProductAndDesign - case "PROFESSIONAL_SERVICES": - *i = ThirdPartyCategoryProfessionalServices - case "RECRUITING": - *i = ThirdPartyCategoryRecruiting - case "SALES": - *i = ThirdPartyCategorySales - case "SECURITY": - *i = ThirdPartyCategorySecurity - case "VERSION_CONTROL": - *i = ThirdPartyCategoryVersionControl - default: - return fmt.Errorf("invalid ThirdPartyCategory value: %q", v) - } - default: - return fmt.Errorf("unsupported type for ThirdPartyCategory: %T", value) - } - - return nil -} - -func (i ThirdPartyCategory) Value() (driver.Value, error) { - return i.String(), nil -} - -func (i ThirdPartyCategory) MarshalJSON() ([]byte, error) { - return json.Marshal(i.String()) -} - -func (i *ThirdPartyCategory) UnmarshalJSON(data []byte) error { - var s string - if err := json.Unmarshal(data, &s); err != nil { - return err - } - - switch s { - case "ANALYTICS": - *i = ThirdPartyCategoryAnalytics - case "CLOUD_MONITORING": - *i = ThirdPartyCategoryCloudMonitoring - case "CLOUD_PROVIDER": - *i = ThirdPartyCategoryCloudProvider - case "COLLABORATION": - *i = ThirdPartyCategoryCollaboration - case "CUSTOMER_SUPPORT": - *i = ThirdPartyCategoryCustomerSupport - case "DATA_STORAGE_AND_PROCESSING": - *i = ThirdPartyCategoryDataStorageAndProcessing - case "DOCUMENT_MANAGEMENT": - *i = ThirdPartyCategoryDocumentManagement - case "EMPLOYEE_MANAGEMENT": - *i = ThirdPartyCategoryEmployeeManagement - case "ENGINEERING": - *i = ThirdPartyCategoryEngineering - case "FINANCE": - *i = ThirdPartyCategoryFinance - case "IDENTITY_PROVIDER": - *i = ThirdPartyCategoryIdentityProvider - case "IT": - *i = ThirdPartyCategoryIT - case "MARKETING": - *i = ThirdPartyCategoryMarketing - case "OFFICE_OPERATIONS": - *i = ThirdPartyCategoryOfficeOperations - case "OTHER": - *i = ThirdPartyCategoryOther - case "PASSWORD_MANAGEMENT": - *i = ThirdPartyCategoryPasswordManagement - case "PRODUCT_AND_DESIGN": - *i = ThirdPartyCategoryProductAndDesign - case "PROFESSIONAL_SERVICES": - *i = ThirdPartyCategoryProfessionalServices - case "RECRUITING": - *i = ThirdPartyCategoryRecruiting - case "SALES": - *i = ThirdPartyCategorySales - case "SECURITY": - *i = ThirdPartyCategorySecurity - case "VERSION_CONTROL": - *i = ThirdPartyCategoryVersionControl - default: - return fmt.Errorf("invalid ThirdPartyCategory value: %q", s) - } - - return nil -} - -func (i *ThirdPartyCategory) UnmarshalText(text []byte) error { - s := string(text) - - switch s { - case "ANALYTICS": - *i = ThirdPartyCategoryAnalytics - case "CLOUD_MONITORING": - *i = ThirdPartyCategoryCloudMonitoring - case "CLOUD_PROVIDER": - *i = ThirdPartyCategoryCloudProvider - case "COLLABORATION": - *i = ThirdPartyCategoryCollaboration - case "CUSTOMER_SUPPORT": - *i = ThirdPartyCategoryCustomerSupport - case "DATA_STORAGE_AND_PROCESSING": - *i = ThirdPartyCategoryDataStorageAndProcessing - case "DOCUMENT_MANAGEMENT": - *i = ThirdPartyCategoryDocumentManagement - case "EMPLOYEE_MANAGEMENT": - *i = ThirdPartyCategoryEmployeeManagement - case "ENGINEERING": - *i = ThirdPartyCategoryEngineering - case "FINANCE": - *i = ThirdPartyCategoryFinance - case "IDENTITY_PROVIDER": - *i = ThirdPartyCategoryIdentityProvider - case "IT": - *i = ThirdPartyCategoryIT - case "MARKETING": - *i = ThirdPartyCategoryMarketing - case "OFFICE_OPERATIONS": - *i = ThirdPartyCategoryOfficeOperations - case "OTHER": - *i = ThirdPartyCategoryOther - case "PASSWORD_MANAGEMENT": - *i = ThirdPartyCategoryPasswordManagement - case "PRODUCT_AND_DESIGN": - *i = ThirdPartyCategoryProductAndDesign - case "PROFESSIONAL_SERVICES": - *i = ThirdPartyCategoryProfessionalServices - case "RECRUITING": - *i = ThirdPartyCategoryRecruiting - case "SALES": - *i = ThirdPartyCategorySales - case "SECURITY": - *i = ThirdPartyCategorySecurity - case "VERSION_CONTROL": - *i = ThirdPartyCategoryVersionControl - default: - return fmt.Errorf("invalid ThirdPartyCategory value: %q", s) +func (v ThirdPartyCategory) String() string { + return string(v) +} + +func (v ThirdPartyCategory) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *ThirdPartyCategory) UnmarshalText(text []byte) error { + val := ThirdPartyCategory(text) + if !val.IsValid() { + return fmt.Errorf("invalid ThirdPartyCategory value: %q", string(text)) } + *v = val + return nil } diff --git a/pkg/coredata/third_party_compliance_report_order_field.go b/pkg/coredata/third_party_compliance_report_order_field.go index 9a42929ca..d636c7975 100644 --- a/pkg/coredata/third_party_compliance_report_order_field.go +++ b/pkg/coredata/third_party_compliance_report_order_field.go @@ -14,6 +14,13 @@ package coredata +import ( + "encoding" + "fmt" + + "go.probo.inc/probo/pkg/page" +) + type ( ThirdPartyComplianceReportOrderField string ) @@ -23,19 +30,50 @@ const ( ThirdPartyComplianceReportOrderFieldCreatedAt ThirdPartyComplianceReportOrderField = "CREATED_AT" ) +var ( + _ page.OrderField = ThirdPartyComplianceReportOrderField("") + _ fmt.Stringer = ThirdPartyComplianceReportOrderField("") + _ encoding.TextMarshaler = ThirdPartyComplianceReportOrderField("") + _ encoding.TextUnmarshaler = (*ThirdPartyComplianceReportOrderField)(nil) +) + +func ThirdPartyComplianceReportOrderFields() []ThirdPartyComplianceReportOrderField { + return []ThirdPartyComplianceReportOrderField{ + ThirdPartyComplianceReportOrderFieldReportDate, + ThirdPartyComplianceReportOrderFieldCreatedAt, + } +} + +func (v ThirdPartyComplianceReportOrderField) IsValid() bool { + switch v { + case + ThirdPartyComplianceReportOrderFieldReportDate, + ThirdPartyComplianceReportOrderFieldCreatedAt: + return true + } + + return false +} + +func (v ThirdPartyComplianceReportOrderField) String() string { + return string(v) +} + +func (v ThirdPartyComplianceReportOrderField) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *ThirdPartyComplianceReportOrderField) UnmarshalText(text []byte) error { + val := ThirdPartyComplianceReportOrderField(text) + if !val.IsValid() { + return fmt.Errorf("invalid ThirdPartyComplianceReportOrderField value: %q", string(text)) + } + + *v = val + + return nil +} + func (p ThirdPartyComplianceReportOrderField) Column() string { return string(p) } - -func (p ThirdPartyComplianceReportOrderField) String() string { - return string(p) -} - -func (p ThirdPartyComplianceReportOrderField) MarshalText() ([]byte, error) { - return []byte(p.String()), nil -} - -func (p *ThirdPartyComplianceReportOrderField) UnmarshalText(text []byte) error { - *p = ThirdPartyComplianceReportOrderField(text) - return nil -} diff --git a/pkg/coredata/third_party_contact_order_field.go b/pkg/coredata/third_party_contact_order_field.go index c1b800a3f..cea47d5bf 100644 --- a/pkg/coredata/third_party_contact_order_field.go +++ b/pkg/coredata/third_party_contact_order_field.go @@ -14,6 +14,13 @@ package coredata +import ( + "encoding" + "fmt" + + "go.probo.inc/probo/pkg/page" +) + type ( ThirdPartyContactOrderField string ) @@ -24,19 +31,52 @@ const ( ThirdPartyContactOrderFieldEmail ThirdPartyContactOrderField = "EMAIL" ) +var ( + _ page.OrderField = ThirdPartyContactOrderField("") + _ fmt.Stringer = ThirdPartyContactOrderField("") + _ encoding.TextMarshaler = ThirdPartyContactOrderField("") + _ encoding.TextUnmarshaler = (*ThirdPartyContactOrderField)(nil) +) + +func ThirdPartyContactOrderFields() []ThirdPartyContactOrderField { + return []ThirdPartyContactOrderField{ + ThirdPartyContactOrderFieldCreatedAt, + ThirdPartyContactOrderFieldFullName, + ThirdPartyContactOrderFieldEmail, + } +} + +func (v ThirdPartyContactOrderField) IsValid() bool { + switch v { + case + ThirdPartyContactOrderFieldCreatedAt, + ThirdPartyContactOrderFieldFullName, + ThirdPartyContactOrderFieldEmail: + return true + } + + return false +} + +func (v ThirdPartyContactOrderField) String() string { + return string(v) +} + +func (v ThirdPartyContactOrderField) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *ThirdPartyContactOrderField) UnmarshalText(text []byte) error { + val := ThirdPartyContactOrderField(text) + if !val.IsValid() { + return fmt.Errorf("invalid ThirdPartyContactOrderField value: %q", string(text)) + } + + *v = val + + return nil +} + func (p ThirdPartyContactOrderField) Column() string { return string(p) } - -func (p ThirdPartyContactOrderField) String() string { - return string(p) -} - -func (p ThirdPartyContactOrderField) MarshalText() ([]byte, error) { - return []byte(p.String()), nil -} - -func (p *ThirdPartyContactOrderField) UnmarshalText(text []byte) error { - *p = ThirdPartyContactOrderField(text) - return nil -} diff --git a/pkg/coredata/third_party_data_privacy_agreement_order_field.go b/pkg/coredata/third_party_data_privacy_agreement_order_field.go index 83edd0568..8b7434cee 100644 --- a/pkg/coredata/third_party_data_privacy_agreement_order_field.go +++ b/pkg/coredata/third_party_data_privacy_agreement_order_field.go @@ -14,6 +14,13 @@ package coredata +import ( + "encoding" + "fmt" + + "go.probo.inc/probo/pkg/page" +) + type ( ThirdPartyDataPrivacyAgreementOrderField string ) @@ -23,19 +30,50 @@ const ( ThirdPartyDataPrivacyAgreementOrderFieldCreatedAt ThirdPartyDataPrivacyAgreementOrderField = "CREATED_AT" ) +var ( + _ page.OrderField = ThirdPartyDataPrivacyAgreementOrderField("") + _ fmt.Stringer = ThirdPartyDataPrivacyAgreementOrderField("") + _ encoding.TextMarshaler = ThirdPartyDataPrivacyAgreementOrderField("") + _ encoding.TextUnmarshaler = (*ThirdPartyDataPrivacyAgreementOrderField)(nil) +) + +func ThirdPartyDataPrivacyAgreementOrderFields() []ThirdPartyDataPrivacyAgreementOrderField { + return []ThirdPartyDataPrivacyAgreementOrderField{ + ThirdPartyDataPrivacyAgreementOrderFieldValidFrom, + ThirdPartyDataPrivacyAgreementOrderFieldCreatedAt, + } +} + +func (v ThirdPartyDataPrivacyAgreementOrderField) IsValid() bool { + switch v { + case + ThirdPartyDataPrivacyAgreementOrderFieldValidFrom, + ThirdPartyDataPrivacyAgreementOrderFieldCreatedAt: + return true + } + + return false +} + +func (v ThirdPartyDataPrivacyAgreementOrderField) String() string { + return string(v) +} + +func (v ThirdPartyDataPrivacyAgreementOrderField) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *ThirdPartyDataPrivacyAgreementOrderField) UnmarshalText(text []byte) error { + val := ThirdPartyDataPrivacyAgreementOrderField(text) + if !val.IsValid() { + return fmt.Errorf("invalid ThirdPartyDataPrivacyAgreementOrderField value: %q", string(text)) + } + + *v = val + + return nil +} + func (p ThirdPartyDataPrivacyAgreementOrderField) Column() string { return string(p) } - -func (p ThirdPartyDataPrivacyAgreementOrderField) String() string { - return string(p) -} - -func (p ThirdPartyDataPrivacyAgreementOrderField) MarshalText() ([]byte, error) { - return []byte(p.String()), nil -} - -func (p *ThirdPartyDataPrivacyAgreementOrderField) UnmarshalText(text []byte) error { - *p = ThirdPartyDataPrivacyAgreementOrderField(text) - return nil -} diff --git a/pkg/coredata/third_party_order_field.go b/pkg/coredata/third_party_order_field.go index e131dace1..7513e0d2e 100644 --- a/pkg/coredata/third_party_order_field.go +++ b/pkg/coredata/third_party_order_field.go @@ -14,6 +14,13 @@ package coredata +import ( + "encoding" + "fmt" + + "go.probo.inc/probo/pkg/page" +) + type ( ThirdPartyOrderField string ) @@ -24,19 +31,52 @@ const ( ThirdPartyOrderFieldName ThirdPartyOrderField = "NAME" ) +var ( + _ page.OrderField = ThirdPartyOrderField("") + _ fmt.Stringer = ThirdPartyOrderField("") + _ encoding.TextMarshaler = ThirdPartyOrderField("") + _ encoding.TextUnmarshaler = (*ThirdPartyOrderField)(nil) +) + +func ThirdPartyOrderFields() []ThirdPartyOrderField { + return []ThirdPartyOrderField{ + ThirdPartyOrderFieldCreatedAt, + ThirdPartyOrderFieldUpdatedAt, + ThirdPartyOrderFieldName, + } +} + +func (v ThirdPartyOrderField) IsValid() bool { + switch v { + case + ThirdPartyOrderFieldCreatedAt, + ThirdPartyOrderFieldUpdatedAt, + ThirdPartyOrderFieldName: + return true + } + + return false +} + +func (v ThirdPartyOrderField) String() string { + return string(v) +} + +func (v ThirdPartyOrderField) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *ThirdPartyOrderField) UnmarshalText(text []byte) error { + val := ThirdPartyOrderField(text) + if !val.IsValid() { + return fmt.Errorf("invalid ThirdPartyOrderField value: %q", string(text)) + } + + *v = val + + return nil +} + func (p ThirdPartyOrderField) Column() string { return string(p) } - -func (p ThirdPartyOrderField) String() string { - return string(p) -} - -func (p ThirdPartyOrderField) MarshalText() ([]byte, error) { - return []byte(p.String()), nil -} - -func (p *ThirdPartyOrderField) UnmarshalText(text []byte) error { - *p = ThirdPartyOrderField(text) - return nil -} diff --git a/pkg/coredata/third_party_risk_assessment_order_field.go b/pkg/coredata/third_party_risk_assessment_order_field.go index 6cb853fdc..f6ebff12f 100644 --- a/pkg/coredata/third_party_risk_assessment_order_field.go +++ b/pkg/coredata/third_party_risk_assessment_order_field.go @@ -14,6 +14,13 @@ package coredata +import ( + "encoding" + "fmt" + + "go.probo.inc/probo/pkg/page" +) + type ( ThirdPartyRiskAssessmentOrderField string ) @@ -23,19 +30,50 @@ const ( ThirdPartyRiskAssessmentOrderFieldExpiresAt ThirdPartyRiskAssessmentOrderField = "EXPIRES_AT" ) +var ( + _ page.OrderField = ThirdPartyRiskAssessmentOrderField("") + _ fmt.Stringer = ThirdPartyRiskAssessmentOrderField("") + _ encoding.TextMarshaler = ThirdPartyRiskAssessmentOrderField("") + _ encoding.TextUnmarshaler = (*ThirdPartyRiskAssessmentOrderField)(nil) +) + +func ThirdPartyRiskAssessmentOrderFields() []ThirdPartyRiskAssessmentOrderField { + return []ThirdPartyRiskAssessmentOrderField{ + ThirdPartyRiskAssessmentOrderFieldCreatedAt, + ThirdPartyRiskAssessmentOrderFieldExpiresAt, + } +} + +func (v ThirdPartyRiskAssessmentOrderField) IsValid() bool { + switch v { + case + ThirdPartyRiskAssessmentOrderFieldCreatedAt, + ThirdPartyRiskAssessmentOrderFieldExpiresAt: + return true + } + + return false +} + +func (v ThirdPartyRiskAssessmentOrderField) String() string { + return string(v) +} + +func (v ThirdPartyRiskAssessmentOrderField) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *ThirdPartyRiskAssessmentOrderField) UnmarshalText(text []byte) error { + val := ThirdPartyRiskAssessmentOrderField(text) + if !val.IsValid() { + return fmt.Errorf("invalid ThirdPartyRiskAssessmentOrderField value: %q", string(text)) + } + + *v = val + + return nil +} + func (p ThirdPartyRiskAssessmentOrderField) Column() string { return string(p) } - -func (p ThirdPartyRiskAssessmentOrderField) String() string { - return string(p) -} - -func (p ThirdPartyRiskAssessmentOrderField) MarshalText() ([]byte, error) { - return []byte(p.String()), nil -} - -func (p *ThirdPartyRiskAssessmentOrderField) UnmarshalText(text []byte) error { - *p = ThirdPartyRiskAssessmentOrderField(text) - return nil -} diff --git a/pkg/coredata/third_party_service_order_field.go b/pkg/coredata/third_party_service_order_field.go index a23407bc9..ce1ea1df0 100644 --- a/pkg/coredata/third_party_service_order_field.go +++ b/pkg/coredata/third_party_service_order_field.go @@ -15,7 +15,10 @@ package coredata import ( + "encoding" "fmt" + + "go.probo.inc/probo/pkg/page" ) type ( @@ -27,26 +30,50 @@ const ( ThirdPartyServiceOrderFieldName ThirdPartyServiceOrderField = "NAME" ) +var ( + _ page.OrderField = ThirdPartyServiceOrderField("") + _ fmt.Stringer = ThirdPartyServiceOrderField("") + _ encoding.TextMarshaler = ThirdPartyServiceOrderField("") + _ encoding.TextUnmarshaler = (*ThirdPartyServiceOrderField)(nil) +) + +func ThirdPartyServiceOrderFields() []ThirdPartyServiceOrderField { + return []ThirdPartyServiceOrderField{ + ThirdPartyServiceOrderFieldCreatedAt, + ThirdPartyServiceOrderFieldName, + } +} + +func (v ThirdPartyServiceOrderField) IsValid() bool { + switch v { + case + ThirdPartyServiceOrderFieldCreatedAt, + ThirdPartyServiceOrderFieldName: + return true + } + + return false +} + +func (v ThirdPartyServiceOrderField) String() string { + return string(v) +} + +func (v ThirdPartyServiceOrderField) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *ThirdPartyServiceOrderField) UnmarshalText(text []byte) error { + val := ThirdPartyServiceOrderField(text) + if !val.IsValid() { + return fmt.Errorf("invalid ThirdPartyServiceOrderField value: %q", string(text)) + } + + *v = val + + return nil +} + func (p ThirdPartyServiceOrderField) Column() string { return string(p) } - -func (p ThirdPartyServiceOrderField) String() string { - return string(p) -} - -func (p ThirdPartyServiceOrderField) MarshalText() ([]byte, error) { - return []byte(p.String()), nil -} - -func (p *ThirdPartyServiceOrderField) UnmarshalText(text []byte) error { - val := string(text) - switch val { - case string(ThirdPartyServiceOrderFieldCreatedAt), - string(ThirdPartyServiceOrderFieldName): - *p = ThirdPartyServiceOrderField(val) - return nil - } - - return fmt.Errorf("invalid ThirdPartyServiceOrderField value: %q", val) -} diff --git a/pkg/coredata/tracker_pattern_match_type.go b/pkg/coredata/tracker_pattern_match_type.go index 030997436..d95be6905 100644 --- a/pkg/coredata/tracker_pattern_match_type.go +++ b/pkg/coredata/tracker_pattern_match_type.go @@ -15,7 +15,7 @@ package coredata import ( - "database/sql/driver" + "encoding" "fmt" ) @@ -27,50 +27,47 @@ const ( TrackerPatternMatchTypeGlob TrackerPatternMatchType = "GLOB" ) +var ( + _ fmt.Stringer = TrackerPatternMatchType("") + _ encoding.TextMarshaler = TrackerPatternMatchType("") + _ encoding.TextUnmarshaler = (*TrackerPatternMatchType)(nil) +) + func TrackerPatternMatchTypes() []TrackerPatternMatchType { return []TrackerPatternMatchType{ TrackerPatternMatchTypeExact, + TrackerPatternMatchTypePrefix, TrackerPatternMatchTypeGlob, } } -func (m TrackerPatternMatchType) String() string { - return string(m) +func (v TrackerPatternMatchType) IsValid() bool { + switch v { + case + TrackerPatternMatchTypeExact, + TrackerPatternMatchTypePrefix, + TrackerPatternMatchTypeGlob: + return true + } + + return false } -func (m *TrackerPatternMatchType) Scan(value any) error { - var v string +func (v TrackerPatternMatchType) String() string { + return string(v) +} - switch val := value.(type) { - case string: - v = val - case []byte: - v = string(val) - default: - return fmt.Errorf("unsupported type for TrackerPatternMatchType: %T", value) +func (v TrackerPatternMatchType) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *TrackerPatternMatchType) UnmarshalText(text []byte) error { + val := TrackerPatternMatchType(text) + if !val.IsValid() { + return fmt.Errorf("invalid TrackerPatternMatchType value: %q", string(text)) } - switch TrackerPatternMatchType(v) { - case TrackerPatternMatchTypeExact: - *m = TrackerPatternMatchTypeExact - case TrackerPatternMatchTypePrefix: - *m = TrackerPatternMatchTypePrefix - case TrackerPatternMatchTypeGlob: - *m = TrackerPatternMatchTypeGlob - default: - return fmt.Errorf("invalid TrackerPatternMatchType value: %q", v) - } + *v = val return nil } - -func (m TrackerPatternMatchType) Value() (driver.Value, error) { - switch m { - case TrackerPatternMatchTypeExact, - TrackerPatternMatchTypePrefix, - TrackerPatternMatchTypeGlob: - return string(m), nil - default: - return nil, fmt.Errorf("invalid TrackerPatternMatchType: %s", m) - } -} diff --git a/pkg/coredata/tracker_pattern_order_field.go b/pkg/coredata/tracker_pattern_order_field.go index 53e95832a..565e9ae23 100644 --- a/pkg/coredata/tracker_pattern_order_field.go +++ b/pkg/coredata/tracker_pattern_order_field.go @@ -14,7 +14,12 @@ package coredata -import "fmt" +import ( + "encoding" + "fmt" + + "go.probo.inc/probo/pkg/page" +) type TrackerPatternOrderField string @@ -26,6 +31,56 @@ const ( TrackerPatternOrderFieldSource TrackerPatternOrderField = "SOURCE" ) +var ( + _ page.OrderField = TrackerPatternOrderField("") + _ fmt.Stringer = TrackerPatternOrderField("") + _ encoding.TextMarshaler = TrackerPatternOrderField("") + _ encoding.TextUnmarshaler = (*TrackerPatternOrderField)(nil) +) + +func TrackerPatternOrderFields() []TrackerPatternOrderField { + return []TrackerPatternOrderField{ + TrackerPatternOrderFieldCreatedAt, + TrackerPatternOrderFieldName, + TrackerPatternOrderFieldLastMatchedAt, + TrackerPatternOrderFieldUpdatedAt, + TrackerPatternOrderFieldSource, + } +} + +func (v TrackerPatternOrderField) IsValid() bool { + switch v { + case + TrackerPatternOrderFieldCreatedAt, + TrackerPatternOrderFieldName, + TrackerPatternOrderFieldLastMatchedAt, + TrackerPatternOrderFieldUpdatedAt, + TrackerPatternOrderFieldSource: + return true + } + + return false +} + +func (v TrackerPatternOrderField) String() string { + return string(v) +} + +func (v TrackerPatternOrderField) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *TrackerPatternOrderField) UnmarshalText(text []byte) error { + val := TrackerPatternOrderField(text) + if !val.IsValid() { + return fmt.Errorf("invalid TrackerPatternOrderField value: %q", string(text)) + } + + *v = val + + return nil +} + func (p TrackerPatternOrderField) Column() string { switch p { case TrackerPatternOrderFieldCreatedAt: @@ -42,33 +97,3 @@ func (p TrackerPatternOrderField) Column() string { panic(fmt.Sprintf("unsupported order by: %s", p)) } - -func (p TrackerPatternOrderField) IsValid() bool { - switch p { - case TrackerPatternOrderFieldCreatedAt, - TrackerPatternOrderFieldName, - TrackerPatternOrderFieldLastMatchedAt, - TrackerPatternOrderFieldUpdatedAt, - TrackerPatternOrderFieldSource: - return true - } - - return false -} - -func (p TrackerPatternOrderField) String() string { - return string(p) -} - -func (p *TrackerPatternOrderField) UnmarshalText(text []byte) error { - *p = TrackerPatternOrderField(text) - if !p.IsValid() { - return fmt.Errorf("%s is not a valid TrackerPatternOrderField", string(text)) - } - - return nil -} - -func (p TrackerPatternOrderField) MarshalText() ([]byte, error) { - return []byte(p.String()), nil -} diff --git a/pkg/coredata/tracker_resource_order_field.go b/pkg/coredata/tracker_resource_order_field.go index 51900101e..819c51890 100644 --- a/pkg/coredata/tracker_resource_order_field.go +++ b/pkg/coredata/tracker_resource_order_field.go @@ -14,7 +14,12 @@ package coredata -import "fmt" +import ( + "encoding" + "fmt" + + "go.probo.inc/probo/pkg/page" +) type TrackerResourceOrderField string @@ -25,6 +30,54 @@ const ( TrackerResourceOrderFieldUpdatedAt TrackerResourceOrderField = "UPDATED_AT" ) +var ( + _ page.OrderField = TrackerResourceOrderField("") + _ fmt.Stringer = TrackerResourceOrderField("") + _ encoding.TextMarshaler = TrackerResourceOrderField("") + _ encoding.TextUnmarshaler = (*TrackerResourceOrderField)(nil) +) + +func TrackerResourceOrderFields() []TrackerResourceOrderField { + return []TrackerResourceOrderField{ + TrackerResourceOrderFieldCreatedAt, + TrackerResourceOrderFieldLastDetectedAt, + TrackerResourceOrderFieldOrigin, + TrackerResourceOrderFieldUpdatedAt, + } +} + +func (v TrackerResourceOrderField) IsValid() bool { + switch v { + case + TrackerResourceOrderFieldCreatedAt, + TrackerResourceOrderFieldLastDetectedAt, + TrackerResourceOrderFieldOrigin, + TrackerResourceOrderFieldUpdatedAt: + return true + } + + return false +} + +func (v TrackerResourceOrderField) String() string { + return string(v) +} + +func (v TrackerResourceOrderField) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *TrackerResourceOrderField) UnmarshalText(text []byte) error { + val := TrackerResourceOrderField(text) + if !val.IsValid() { + return fmt.Errorf("invalid TrackerResourceOrderField value: %q", string(text)) + } + + *v = val + + return nil +} + func (p TrackerResourceOrderField) Column() string { switch p { case TrackerResourceOrderFieldCreatedAt: @@ -39,32 +92,3 @@ func (p TrackerResourceOrderField) Column() string { panic(fmt.Sprintf("unsupported order by: %s", p)) } - -func (p TrackerResourceOrderField) IsValid() bool { - switch p { - case TrackerResourceOrderFieldCreatedAt, - TrackerResourceOrderFieldLastDetectedAt, - TrackerResourceOrderFieldOrigin, - TrackerResourceOrderFieldUpdatedAt: - return true - } - - return false -} - -func (p TrackerResourceOrderField) String() string { - return string(p) -} - -func (p *TrackerResourceOrderField) UnmarshalText(text []byte) error { - *p = TrackerResourceOrderField(text) - if !p.IsValid() { - return fmt.Errorf("%s is not a valid TrackerResourceOrderField", string(text)) - } - - return nil -} - -func (p TrackerResourceOrderField) MarshalText() ([]byte, error) { - return []byte(p.String()), nil -} diff --git a/pkg/coredata/tracker_resource_type.go b/pkg/coredata/tracker_resource_type.go index 3dfad4758..8e88f6442 100644 --- a/pkg/coredata/tracker_resource_type.go +++ b/pkg/coredata/tracker_resource_type.go @@ -15,7 +15,7 @@ package coredata import ( - "database/sql/driver" + "encoding" "fmt" ) @@ -33,6 +33,12 @@ const ( TrackerResourceTypeServiceWorker TrackerResourceType = "SERVICE_WORKER" ) +var ( + _ fmt.Stringer = TrackerResourceType("") + _ encoding.TextMarshaler = TrackerResourceType("") + _ encoding.TextUnmarshaler = (*TrackerResourceType)(nil) +) + func TrackerResourceTypes() []TrackerResourceType { return []TrackerResourceType{ TrackerResourceTypeScript, @@ -47,51 +53,10 @@ func TrackerResourceTypes() []TrackerResourceType { } } -func (s TrackerResourceType) String() string { - return string(s) -} - -func (s *TrackerResourceType) Scan(value any) error { - var v string - - switch val := value.(type) { - case string: - v = val - case []byte: - v = string(val) - default: - return fmt.Errorf("unsupported type for TrackerResourceType: %T", value) - } - - switch TrackerResourceType(v) { - case TrackerResourceTypeScript: - *s = TrackerResourceTypeScript - case TrackerResourceTypeIframe: - *s = TrackerResourceTypeIframe - case TrackerResourceTypeImage: - *s = TrackerResourceTypeImage - case TrackerResourceTypeStylesheet: - *s = TrackerResourceTypeStylesheet - case TrackerResourceTypeFont: - *s = TrackerResourceTypeFont - case TrackerResourceTypeBeacon: - *s = TrackerResourceTypeBeacon - case TrackerResourceTypeFetch: - *s = TrackerResourceTypeFetch - case TrackerResourceTypeMedia: - *s = TrackerResourceTypeMedia - case TrackerResourceTypeServiceWorker: - *s = TrackerResourceTypeServiceWorker - default: - return fmt.Errorf("invalid TrackerResourceType value: %q", v) - } - - return nil -} - -func (s TrackerResourceType) Value() (driver.Value, error) { - switch s { - case TrackerResourceTypeScript, +func (v TrackerResourceType) IsValid() bool { + switch v { + case + TrackerResourceTypeScript, TrackerResourceTypeIframe, TrackerResourceTypeImage, TrackerResourceTypeStylesheet, @@ -100,8 +65,27 @@ func (s TrackerResourceType) Value() (driver.Value, error) { TrackerResourceTypeFetch, TrackerResourceTypeMedia, TrackerResourceTypeServiceWorker: - return string(s), nil - default: - return nil, fmt.Errorf("invalid TrackerResourceType: %s", s) + return true } + + return false +} + +func (v TrackerResourceType) String() string { + return string(v) +} + +func (v TrackerResourceType) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *TrackerResourceType) UnmarshalText(text []byte) error { + val := TrackerResourceType(text) + if !val.IsValid() { + return fmt.Errorf("invalid TrackerResourceType value: %q", string(text)) + } + + *v = val + + return nil } diff --git a/pkg/coredata/tracker_type.go b/pkg/coredata/tracker_type.go index 0773a0265..58a80ee3d 100644 --- a/pkg/coredata/tracker_type.go +++ b/pkg/coredata/tracker_type.go @@ -15,7 +15,7 @@ package coredata import ( - "database/sql/driver" + "encoding" "fmt" ) @@ -29,6 +29,12 @@ const ( TrackerTypeCacheStorage TrackerType = "CACHE_STORAGE" ) +var ( + _ fmt.Stringer = TrackerType("") + _ encoding.TextMarshaler = TrackerType("") + _ encoding.TextUnmarshaler = (*TrackerType)(nil) +) + func TrackerTypes() []TrackerType { return []TrackerType{ TrackerTypeCookie, @@ -39,49 +45,35 @@ func TrackerTypes() []TrackerType { } } -func (s TrackerType) String() string { - return string(s) -} - -func (s *TrackerType) Scan(value any) error { - var v string - - switch val := value.(type) { - case string: - v = val - case []byte: - v = string(val) - default: - return fmt.Errorf("unsupported type for TrackerType: %T", value) - } - - switch TrackerType(v) { - case TrackerTypeCookie: - *s = TrackerTypeCookie - case TrackerTypeLocalStorage: - *s = TrackerTypeLocalStorage - case TrackerTypeSessionStorage: - *s = TrackerTypeSessionStorage - case TrackerTypeIndexedDB: - *s = TrackerTypeIndexedDB - case TrackerTypeCacheStorage: - *s = TrackerTypeCacheStorage - default: - return fmt.Errorf("invalid TrackerType value: %q", v) - } - - return nil -} - -func (s TrackerType) Value() (driver.Value, error) { - switch s { - case TrackerTypeCookie, +func (v TrackerType) IsValid() bool { + switch v { + case + TrackerTypeCookie, TrackerTypeLocalStorage, TrackerTypeSessionStorage, TrackerTypeIndexedDB, TrackerTypeCacheStorage: - return string(s), nil - default: - return nil, fmt.Errorf("invalid TrackerType: %s", s) + return true } + + return false +} + +func (v TrackerType) String() string { + return string(v) +} + +func (v TrackerType) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *TrackerType) UnmarshalText(text []byte) error { + val := TrackerType(text) + if !val.IsValid() { + return fmt.Errorf("invalid TrackerType value: %q", string(text)) + } + + *v = val + + return nil } diff --git a/pkg/coredata/transfer_impact_assessment_order_field.go b/pkg/coredata/transfer_impact_assessment_order_field.go index 6952dfe40..5cd3f511c 100644 --- a/pkg/coredata/transfer_impact_assessment_order_field.go +++ b/pkg/coredata/transfer_impact_assessment_order_field.go @@ -14,7 +14,12 @@ package coredata -import "fmt" +import ( + "encoding" + "fmt" + + "go.probo.inc/probo/pkg/page" +) type TransferImpactAssessmentOrderField string @@ -22,25 +27,48 @@ const ( TransferImpactAssessmentOrderFieldCreatedAt TransferImpactAssessmentOrderField = "CREATED_AT" ) +var ( + _ page.OrderField = TransferImpactAssessmentOrderField("") + _ fmt.Stringer = TransferImpactAssessmentOrderField("") + _ encoding.TextMarshaler = TransferImpactAssessmentOrderField("") + _ encoding.TextUnmarshaler = (*TransferImpactAssessmentOrderField)(nil) +) + +func TransferImpactAssessmentOrderFields() []TransferImpactAssessmentOrderField { + return []TransferImpactAssessmentOrderField{ + TransferImpactAssessmentOrderFieldCreatedAt, + } +} + +func (v TransferImpactAssessmentOrderField) IsValid() bool { + switch v { + case + TransferImpactAssessmentOrderFieldCreatedAt: + return true + } + + return false +} + +func (v TransferImpactAssessmentOrderField) String() string { + return string(v) +} + +func (v TransferImpactAssessmentOrderField) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *TransferImpactAssessmentOrderField) UnmarshalText(text []byte) error { + val := TransferImpactAssessmentOrderField(text) + if !val.IsValid() { + return fmt.Errorf("invalid TransferImpactAssessmentOrderField value: %q", string(text)) + } + + *v = val + + return nil +} + func (p TransferImpactAssessmentOrderField) Column() string { return string(p) } - -func (p TransferImpactAssessmentOrderField) String() string { - return string(p) -} - -func (p TransferImpactAssessmentOrderField) MarshalText() ([]byte, error) { - return []byte(p.String()), nil -} - -func (p *TransferImpactAssessmentOrderField) UnmarshalText(text []byte) error { - val := string(text) - switch val { - case string(TransferImpactAssessmentOrderFieldCreatedAt): - *p = TransferImpactAssessmentOrderFieldCreatedAt - return nil - } - - return fmt.Errorf("invalid TransferImpactAssessmentOrderField value: %q", val) -} diff --git a/pkg/coredata/trust_center_access_order_field.go b/pkg/coredata/trust_center_access_order_field.go index 4e25b9b70..181d1e1db 100644 --- a/pkg/coredata/trust_center_access_order_field.go +++ b/pkg/coredata/trust_center_access_order_field.go @@ -14,7 +14,12 @@ package coredata -import "fmt" +import ( + "encoding" + "fmt" + + "go.probo.inc/probo/pkg/page" +) type TrustCenterAccessOrderField string @@ -22,8 +27,46 @@ const ( TrustCenterAccessOrderFieldCreatedAt TrustCenterAccessOrderField = "CREATED_AT" ) -func (tcaof TrustCenterAccessOrderField) String() string { - return string(tcaof) +var ( + _ page.OrderField = TrustCenterAccessOrderField("") + _ fmt.Stringer = TrustCenterAccessOrderField("") + _ encoding.TextMarshaler = TrustCenterAccessOrderField("") + _ encoding.TextUnmarshaler = (*TrustCenterAccessOrderField)(nil) +) + +func TrustCenterAccessOrderFields() []TrustCenterAccessOrderField { + return []TrustCenterAccessOrderField{ + TrustCenterAccessOrderFieldCreatedAt, + } +} + +func (v TrustCenterAccessOrderField) IsValid() bool { + switch v { + case + TrustCenterAccessOrderFieldCreatedAt: + return true + } + + return false +} + +func (v TrustCenterAccessOrderField) String() string { + return string(v) +} + +func (v TrustCenterAccessOrderField) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *TrustCenterAccessOrderField) UnmarshalText(text []byte) error { + val := TrustCenterAccessOrderField(text) + if !val.IsValid() { + return fmt.Errorf("invalid TrustCenterAccessOrderField value: %q", string(text)) + } + + *v = val + + return nil } func (tcaof TrustCenterAccessOrderField) Column() string { diff --git a/pkg/coredata/trust_center_access_state.go b/pkg/coredata/trust_center_access_state.go index 31a442c48..e67d76412 100644 --- a/pkg/coredata/trust_center_access_state.go +++ b/pkg/coredata/trust_center_access_state.go @@ -15,7 +15,7 @@ package coredata import ( - "database/sql/driver" + "encoding" "fmt" ) @@ -26,34 +26,45 @@ const ( TrustCenterAccessStateInactive TrustCenterAccessState = "INACTIVE" ) -func (s TrustCenterAccessState) String() string { - return string(s) +var ( + _ fmt.Stringer = TrustCenterAccessState("") + _ encoding.TextMarshaler = TrustCenterAccessState("") + _ encoding.TextUnmarshaler = (*TrustCenterAccessState)(nil) +) + +func TrustCenterAccessStates() []TrustCenterAccessState { + return []TrustCenterAccessState{ + TrustCenterAccessStateActive, + TrustCenterAccessStateInactive, + } } -func (s *TrustCenterAccessState) Scan(value any) error { - var str string - - switch v := value.(type) { - case string: - str = v - case []byte: - str = string(v) - default: - return fmt.Errorf("unsupported type for TrustCenterAccessState: %T", value) +func (v TrustCenterAccessState) IsValid() bool { + switch v { + case + TrustCenterAccessStateActive, + TrustCenterAccessStateInactive: + return true } - switch str { - case "ACTIVE": - *s = TrustCenterAccessStateActive - case "INACTIVE": - *s = TrustCenterAccessStateInactive - default: - return fmt.Errorf("invalid TrustCenterAccessState value: %q", str) + return false +} + +func (v TrustCenterAccessState) String() string { + return string(v) +} + +func (v TrustCenterAccessState) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *TrustCenterAccessState) UnmarshalText(text []byte) error { + val := TrustCenterAccessState(text) + if !val.IsValid() { + return fmt.Errorf("invalid TrustCenterAccessState value: %q", string(text)) } + *v = val + return nil } - -func (s TrustCenterAccessState) Value() (driver.Value, error) { - return s.String(), nil -} diff --git a/pkg/coredata/trust_center_document_access_order_field.go b/pkg/coredata/trust_center_document_access_order_field.go index a4679ea27..bb556832f 100644 --- a/pkg/coredata/trust_center_document_access_order_field.go +++ b/pkg/coredata/trust_center_document_access_order_field.go @@ -15,7 +15,10 @@ package coredata import ( + "encoding" "fmt" + + "go.probo.inc/probo/pkg/page" ) type TrustCenterDocumentAccessOrderField string @@ -24,25 +27,48 @@ const ( TrustCenterDocumentAccessOrderFieldCreatedAt TrustCenterDocumentAccessOrderField = "CREATED_AT" ) +var ( + _ page.OrderField = TrustCenterDocumentAccessOrderField("") + _ fmt.Stringer = TrustCenterDocumentAccessOrderField("") + _ encoding.TextMarshaler = TrustCenterDocumentAccessOrderField("") + _ encoding.TextUnmarshaler = (*TrustCenterDocumentAccessOrderField)(nil) +) + +func TrustCenterDocumentAccessOrderFields() []TrustCenterDocumentAccessOrderField { + return []TrustCenterDocumentAccessOrderField{ + TrustCenterDocumentAccessOrderFieldCreatedAt, + } +} + +func (v TrustCenterDocumentAccessOrderField) IsValid() bool { + switch v { + case + TrustCenterDocumentAccessOrderFieldCreatedAt: + return true + } + + return false +} + +func (v TrustCenterDocumentAccessOrderField) String() string { + return string(v) +} + +func (v TrustCenterDocumentAccessOrderField) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *TrustCenterDocumentAccessOrderField) UnmarshalText(text []byte) error { + val := TrustCenterDocumentAccessOrderField(text) + if !val.IsValid() { + return fmt.Errorf("invalid TrustCenterDocumentAccessOrderField value: %q", string(text)) + } + + *v = val + + return nil +} + func (tcdaof TrustCenterDocumentAccessOrderField) Column() string { return string(tcdaof) } - -func (tcdaof TrustCenterDocumentAccessOrderField) String() string { - return string(tcdaof) -} - -func (tcdaof TrustCenterDocumentAccessOrderField) MarshalText() ([]byte, error) { - return []byte(tcdaof.String()), nil -} - -func (tcdaof *TrustCenterDocumentAccessOrderField) UnmarshalText(text []byte) error { - val := string(text) - switch val { - case string(TrustCenterDocumentAccessOrderFieldCreatedAt): - *tcdaof = TrustCenterDocumentAccessOrderField(val) - return nil - } - - return fmt.Errorf("invalid TrustCenterDocumentAccessOrderField value: %q", val) -} diff --git a/pkg/coredata/trust_center_document_access_status.go b/pkg/coredata/trust_center_document_access_status.go index 5fd4828ed..1bcf8ac99 100644 --- a/pkg/coredata/trust_center_document_access_status.go +++ b/pkg/coredata/trust_center_document_access_status.go @@ -15,7 +15,7 @@ package coredata import ( - "database/sql/driver" + "encoding" "fmt" ) @@ -28,38 +28,49 @@ const ( TrustCenterDocumentAccessStatusRevoked TrustCenterDocumentAccessStatus = "REVOKED" ) -func (tcdas TrustCenterDocumentAccessStatus) String() string { - return string(tcdas) +var ( + _ fmt.Stringer = TrustCenterDocumentAccessStatus("") + _ encoding.TextMarshaler = TrustCenterDocumentAccessStatus("") + _ encoding.TextUnmarshaler = (*TrustCenterDocumentAccessStatus)(nil) +) + +func TrustCenterDocumentAccessStatuses() []TrustCenterDocumentAccessStatus { + return []TrustCenterDocumentAccessStatus{ + TrustCenterDocumentAccessStatusRequested, + TrustCenterDocumentAccessStatusGranted, + TrustCenterDocumentAccessStatusRejected, + TrustCenterDocumentAccessStatusRevoked, + } } -func (tcdas *TrustCenterDocumentAccessStatus) Scan(value any) error { - var s string - - switch v := value.(type) { - case string: - s = v - case []byte: - s = string(v) - default: - return fmt.Errorf("unsupported type for TrustCenterDocumentAccessStatus: %T", value) +func (v TrustCenterDocumentAccessStatus) IsValid() bool { + switch v { + case + TrustCenterDocumentAccessStatusRequested, + TrustCenterDocumentAccessStatusGranted, + TrustCenterDocumentAccessStatusRejected, + TrustCenterDocumentAccessStatusRevoked: + return true } - switch s { - case "REQUESTED": - *tcdas = TrustCenterDocumentAccessStatusRequested - case "GRANTED": - *tcdas = TrustCenterDocumentAccessStatusGranted - case "REJECTED": - *tcdas = TrustCenterDocumentAccessStatusRejected - case "REVOKED": - *tcdas = TrustCenterDocumentAccessStatusRevoked - default: - return fmt.Errorf("invalid TrustCenterDocumentAccessStatus value: %q", s) + return false +} + +func (v TrustCenterDocumentAccessStatus) String() string { + return string(v) +} + +func (v TrustCenterDocumentAccessStatus) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *TrustCenterDocumentAccessStatus) UnmarshalText(text []byte) error { + val := TrustCenterDocumentAccessStatus(text) + if !val.IsValid() { + return fmt.Errorf("invalid TrustCenterDocumentAccessStatus value: %q", string(text)) } + *v = val + return nil } - -func (tcdas TrustCenterDocumentAccessStatus) Value() (driver.Value, error) { - return tcdas.String(), nil -} diff --git a/pkg/coredata/trust_center_file_order_field.go b/pkg/coredata/trust_center_file_order_field.go index 7e56c3aac..e3dac8bee 100644 --- a/pkg/coredata/trust_center_file_order_field.go +++ b/pkg/coredata/trust_center_file_order_field.go @@ -14,6 +14,13 @@ package coredata +import ( + "encoding" + "fmt" + + "go.probo.inc/probo/pkg/page" +) + type ( TrustCenterFileOrderField string ) @@ -24,6 +31,52 @@ const ( TrustCenterFileOrderFieldUpdatedAt TrustCenterFileOrderField = "UPDATED_AT" ) +var ( + _ page.OrderField = TrustCenterFileOrderField("") + _ fmt.Stringer = TrustCenterFileOrderField("") + _ encoding.TextMarshaler = TrustCenterFileOrderField("") + _ encoding.TextUnmarshaler = (*TrustCenterFileOrderField)(nil) +) + +func TrustCenterFileOrderFields() []TrustCenterFileOrderField { + return []TrustCenterFileOrderField{ + TrustCenterFileOrderFieldName, + TrustCenterFileOrderFieldCreatedAt, + TrustCenterFileOrderFieldUpdatedAt, + } +} + +func (v TrustCenterFileOrderField) IsValid() bool { + switch v { + case + TrustCenterFileOrderFieldName, + TrustCenterFileOrderFieldCreatedAt, + TrustCenterFileOrderFieldUpdatedAt: + return true + } + + return false +} + +func (v TrustCenterFileOrderField) String() string { + return string(v) +} + +func (v TrustCenterFileOrderField) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *TrustCenterFileOrderField) UnmarshalText(text []byte) error { + val := TrustCenterFileOrderField(text) + if !val.IsValid() { + return fmt.Errorf("invalid TrustCenterFileOrderField value: %q", string(text)) + } + + *v = val + + return nil +} + func (p TrustCenterFileOrderField) Column() string { switch p { case TrustCenterFileOrderFieldName: @@ -36,16 +89,3 @@ func (p TrustCenterFileOrderField) Column() string { return string(p) } } - -func (p TrustCenterFileOrderField) String() string { - return string(p) -} - -func (p TrustCenterFileOrderField) MarshalText() ([]byte, error) { - return []byte(p.String()), nil -} - -func (p *TrustCenterFileOrderField) UnmarshalText(text []byte) error { - *p = TrustCenterFileOrderField(text) - return nil -} diff --git a/pkg/coredata/trust_center_order_field.go b/pkg/coredata/trust_center_order_field.go index d36d8a9b5..9b3e48682 100644 --- a/pkg/coredata/trust_center_order_field.go +++ b/pkg/coredata/trust_center_order_field.go @@ -14,25 +14,61 @@ package coredata +import ( + "encoding" + "fmt" + + "go.probo.inc/probo/pkg/page" +) + type TrustCenterOrderField string const ( TrustCenterOrderFieldCreatedAt TrustCenterOrderField = "CREATED_AT" ) +var ( + _ page.OrderField = TrustCenterOrderField("") + _ fmt.Stringer = TrustCenterOrderField("") + _ encoding.TextMarshaler = TrustCenterOrderField("") + _ encoding.TextUnmarshaler = (*TrustCenterOrderField)(nil) +) + +func TrustCenterOrderFields() []TrustCenterOrderField { + return []TrustCenterOrderField{ + TrustCenterOrderFieldCreatedAt, + } +} + +func (v TrustCenterOrderField) IsValid() bool { + switch v { + case + TrustCenterOrderFieldCreatedAt: + return true + } + + return false +} + +func (v TrustCenterOrderField) String() string { + return string(v) +} + +func (v TrustCenterOrderField) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *TrustCenterOrderField) UnmarshalText(text []byte) error { + val := TrustCenterOrderField(text) + if !val.IsValid() { + return fmt.Errorf("invalid TrustCenterOrderField value: %q", string(text)) + } + + *v = val + + return nil +} + func (p TrustCenterOrderField) Column() string { return string(p) } - -func (p TrustCenterOrderField) String() string { - return string(p) -} - -func (p TrustCenterOrderField) MarshalText() ([]byte, error) { - return []byte(p.String()), nil -} - -func (p *TrustCenterOrderField) UnmarshalText(text []byte) error { - *p = TrustCenterOrderField(text) - return nil -} diff --git a/pkg/coredata/trust_center_reference_order_field.go b/pkg/coredata/trust_center_reference_order_field.go index febc575ac..5da836e36 100644 --- a/pkg/coredata/trust_center_reference_order_field.go +++ b/pkg/coredata/trust_center_reference_order_field.go @@ -14,6 +14,13 @@ package coredata +import ( + "encoding" + "fmt" + + "go.probo.inc/probo/pkg/page" +) + type ( TrustCenterReferenceOrderField string ) @@ -25,6 +32,54 @@ const ( TrustCenterReferenceOrderFieldUpdatedAt TrustCenterReferenceOrderField = "UPDATED_AT" ) +var ( + _ page.OrderField = TrustCenterReferenceOrderField("") + _ fmt.Stringer = TrustCenterReferenceOrderField("") + _ encoding.TextMarshaler = TrustCenterReferenceOrderField("") + _ encoding.TextUnmarshaler = (*TrustCenterReferenceOrderField)(nil) +) + +func TrustCenterReferenceOrderFields() []TrustCenterReferenceOrderField { + return []TrustCenterReferenceOrderField{ + TrustCenterReferenceOrderFieldRank, + TrustCenterReferenceOrderFieldName, + TrustCenterReferenceOrderFieldCreatedAt, + TrustCenterReferenceOrderFieldUpdatedAt, + } +} + +func (v TrustCenterReferenceOrderField) IsValid() bool { + switch v { + case + TrustCenterReferenceOrderFieldRank, + TrustCenterReferenceOrderFieldName, + TrustCenterReferenceOrderFieldCreatedAt, + TrustCenterReferenceOrderFieldUpdatedAt: + return true + } + + return false +} + +func (v TrustCenterReferenceOrderField) String() string { + return string(v) +} + +func (v TrustCenterReferenceOrderField) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *TrustCenterReferenceOrderField) UnmarshalText(text []byte) error { + val := TrustCenterReferenceOrderField(text) + if !val.IsValid() { + return fmt.Errorf("invalid TrustCenterReferenceOrderField value: %q", string(text)) + } + + *v = val + + return nil +} + func (p TrustCenterReferenceOrderField) Column() string { switch p { case TrustCenterReferenceOrderFieldRank: @@ -39,16 +94,3 @@ func (p TrustCenterReferenceOrderField) Column() string { return string(p) } } - -func (p TrustCenterReferenceOrderField) String() string { - return string(p) -} - -func (p TrustCenterReferenceOrderField) MarshalText() ([]byte, error) { - return []byte(p.String()), nil -} - -func (p *TrustCenterReferenceOrderField) UnmarshalText(text []byte) error { - *p = TrustCenterReferenceOrderField(text) - return nil -} diff --git a/pkg/coredata/trust_center_visibility.go b/pkg/coredata/trust_center_visibility.go index 2e576f00c..0922c0c63 100644 --- a/pkg/coredata/trust_center_visibility.go +++ b/pkg/coredata/trust_center_visibility.go @@ -15,7 +15,7 @@ package coredata import ( - "database/sql/driver" + "encoding" "fmt" ) @@ -27,6 +27,12 @@ const ( TrustCenterVisibilityPublic TrustCenterVisibility = "PUBLIC" ) +var ( + _ fmt.Stringer = TrustCenterVisibility("") + _ encoding.TextMarshaler = TrustCenterVisibility("") + _ encoding.TextUnmarshaler = (*TrustCenterVisibility)(nil) +) + func TrustCenterVisibilities() []TrustCenterVisibility { return []TrustCenterVisibility{ TrustCenterVisibilityNone, @@ -35,36 +41,33 @@ func TrustCenterVisibilities() []TrustCenterVisibility { } } -func (tcv TrustCenterVisibility) String() string { - return string(tcv) +func (v TrustCenterVisibility) IsValid() bool { + switch v { + case + TrustCenterVisibilityNone, + TrustCenterVisibilityPrivate, + TrustCenterVisibilityPublic: + return true + } + + return false } -func (tcv *TrustCenterVisibility) Scan(value any) error { - var s string +func (v TrustCenterVisibility) String() string { + return string(v) +} - switch v := value.(type) { - case string: - s = v - case []byte: - s = string(v) - default: - return fmt.Errorf("unsupported type for TrustCenterVisibility: %T", value) +func (v TrustCenterVisibility) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *TrustCenterVisibility) UnmarshalText(text []byte) error { + val := TrustCenterVisibility(text) + if !val.IsValid() { + return fmt.Errorf("invalid TrustCenterVisibility value: %q", string(text)) } - switch s { - case "NONE": - *tcv = TrustCenterVisibilityNone - case "PRIVATE": - *tcv = TrustCenterVisibilityPrivate - case "PUBLIC": - *tcv = TrustCenterVisibilityPublic - default: - return fmt.Errorf("invalid TrustCenterVisibility value: %q", s) - } + *v = val return nil } - -func (tcv TrustCenterVisibility) Value() (driver.Value, error) { - return tcv.String(), nil -} diff --git a/pkg/coredata/user_auth_method.go b/pkg/coredata/user_auth_method.go index d9b2e3ced..acb8d63fd 100644 --- a/pkg/coredata/user_auth_method.go +++ b/pkg/coredata/user_auth_method.go @@ -14,9 +14,57 @@ package coredata +import ( + "encoding" + "fmt" +) + type UserAuthMethod string const ( UserAuthMethodPassword UserAuthMethod = "PASSWORD" UserAuthMethodSAML UserAuthMethod = "SAML" ) + +var ( + _ fmt.Stringer = UserAuthMethod("") + _ encoding.TextMarshaler = UserAuthMethod("") + _ encoding.TextUnmarshaler = (*UserAuthMethod)(nil) +) + +func UserAuthMethods() []UserAuthMethod { + return []UserAuthMethod{ + UserAuthMethodPassword, + UserAuthMethodSAML, + } +} + +func (v UserAuthMethod) IsValid() bool { + switch v { + case + UserAuthMethodPassword, + UserAuthMethodSAML: + return true + } + + return false +} + +func (v UserAuthMethod) String() string { + return string(v) +} + +func (v UserAuthMethod) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *UserAuthMethod) UnmarshalText(text []byte) error { + val := UserAuthMethod(text) + if !val.IsValid() { + return fmt.Errorf("invalid UserAuthMethod value: %q", string(text)) + } + + *v = val + + return nil +} diff --git a/pkg/coredata/webhook_event_order_field.go b/pkg/coredata/webhook_event_order_field.go index bd85a3a0d..0de33a59f 100644 --- a/pkg/coredata/webhook_event_order_field.go +++ b/pkg/coredata/webhook_event_order_field.go @@ -15,7 +15,10 @@ package coredata import ( + "encoding" "fmt" + + "go.probo.inc/probo/pkg/page" ) type ( @@ -26,32 +29,48 @@ const ( WebhookEventOrderFieldCreatedAt WebhookEventOrderField = "CREATED_AT" ) -func (p WebhookEventOrderField) Column() string { - return string(p) +var ( + _ page.OrderField = WebhookEventOrderField("") + _ fmt.Stringer = WebhookEventOrderField("") + _ encoding.TextMarshaler = WebhookEventOrderField("") + _ encoding.TextUnmarshaler = (*WebhookEventOrderField)(nil) +) + +func WebhookEventOrderFields() []WebhookEventOrderField { + return []WebhookEventOrderField{ + WebhookEventOrderFieldCreatedAt, + } } -func (p WebhookEventOrderField) String() string { - return string(p) -} - -func (p WebhookEventOrderField) IsValid() bool { - switch p { - case WebhookEventOrderFieldCreatedAt: +func (v WebhookEventOrderField) IsValid() bool { + switch v { + case + WebhookEventOrderFieldCreatedAt: return true } return false } -func (p WebhookEventOrderField) MarshalText() ([]byte, error) { - return []byte(p.String()), nil +func (v WebhookEventOrderField) String() string { + return string(v) } -func (p *WebhookEventOrderField) UnmarshalText(text []byte) error { - *p = WebhookEventOrderField(text) - if !p.IsValid() { - return fmt.Errorf("%s is not a valid WebhookEventOrderField", string(text)) +func (v WebhookEventOrderField) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *WebhookEventOrderField) UnmarshalText(text []byte) error { + val := WebhookEventOrderField(text) + if !val.IsValid() { + return fmt.Errorf("invalid WebhookEventOrderField value: %q", string(text)) } + *v = val + return nil } + +func (p WebhookEventOrderField) Column() string { + return string(p) +} diff --git a/pkg/coredata/webhook_event_status.go b/pkg/coredata/webhook_event_status.go index daae5aedd..82abd81ad 100644 --- a/pkg/coredata/webhook_event_status.go +++ b/pkg/coredata/webhook_event_status.go @@ -15,7 +15,7 @@ package coredata import ( - "database/sql/driver" + "encoding" "fmt" ) @@ -27,43 +27,47 @@ const ( WebhookEventStatusFailed WebhookEventStatus = "FAILED" ) -func (s WebhookEventStatus) String() string { - return string(s) +var ( + _ fmt.Stringer = WebhookEventStatus("") + _ encoding.TextMarshaler = WebhookEventStatus("") + _ encoding.TextUnmarshaler = (*WebhookEventStatus)(nil) +) + +func WebhookEventStatuses() []WebhookEventStatus { + return []WebhookEventStatus{ + WebhookEventStatusPending, + WebhookEventStatusSucceeded, + WebhookEventStatusFailed, + } } -func (s WebhookEventStatus) IsValid() bool { - switch s { - case WebhookEventStatusPending, WebhookEventStatusSucceeded, WebhookEventStatusFailed: +func (v WebhookEventStatus) IsValid() bool { + switch v { + case + WebhookEventStatusPending, + WebhookEventStatusSucceeded, + WebhookEventStatusFailed: return true } return false } -func (s WebhookEventStatus) MarshalText() ([]byte, error) { - return []byte(s.String()), nil +func (v WebhookEventStatus) String() string { + return string(v) } -func (s *WebhookEventStatus) UnmarshalText(text []byte) error { - *s = WebhookEventStatus(text) - if !s.IsValid() { - return fmt.Errorf("%s is not a valid WebhookEventStatus", string(text)) +func (v WebhookEventStatus) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *WebhookEventStatus) UnmarshalText(text []byte) error { + val := WebhookEventStatus(text) + if !val.IsValid() { + return fmt.Errorf("invalid WebhookEventStatus value: %q", string(text)) } + *v = val + return nil } - -func (s *WebhookEventStatus) Scan(value any) error { - switch v := value.(type) { - case string: - return s.UnmarshalText([]byte(v)) - case []byte: - return s.UnmarshalText(v) - default: - return fmt.Errorf("unsupported type for WebhookEventStatus: %T", value) - } -} - -func (s WebhookEventStatus) Value() (driver.Value, error) { - return s.String(), nil -} diff --git a/pkg/coredata/webhook_event_type.go b/pkg/coredata/webhook_event_type.go index 062e33cf2..6bff3f1f4 100644 --- a/pkg/coredata/webhook_event_type.go +++ b/pkg/coredata/webhook_event_type.go @@ -16,6 +16,7 @@ package coredata import ( "database/sql/driver" + "encoding" "fmt" "strings" ) @@ -34,53 +35,49 @@ const ( WebhookEventTypeObligationDeleted WebhookEventType = "obligation:deleted" ) -func (w WebhookEventType) String() string { - return string(w) -} +var ( + _ fmt.Stringer = WebhookEventType("") + _ encoding.TextMarshaler = WebhookEventType("") + _ encoding.TextUnmarshaler = (*WebhookEventType)(nil) +) -func (w WebhookEventType) IsValid() bool { - switch w { - case WebhookEventTypeThirdPartyCreated, WebhookEventTypeThirdPartyUpdated, WebhookEventTypeThirdPartyDeleted, - WebhookEventTypeUserCreated, WebhookEventTypeUserUpdated, WebhookEventTypeUserDeleted, - WebhookEventTypeObligationCreated, WebhookEventTypeObligationUpdated, WebhookEventTypeObligationDeleted: +func (v WebhookEventType) IsValid() bool { + switch v { + case + WebhookEventTypeThirdPartyCreated, + WebhookEventTypeThirdPartyUpdated, + WebhookEventTypeThirdPartyDeleted, + WebhookEventTypeUserCreated, + WebhookEventTypeUserUpdated, + WebhookEventTypeUserDeleted, + WebhookEventTypeObligationCreated, + WebhookEventTypeObligationUpdated, + WebhookEventTypeObligationDeleted: return true } return false } -func (w WebhookEventType) MarshalText() ([]byte, error) { - return []byte(w.String()), nil +func (v WebhookEventType) String() string { + return string(v) } -func (w *WebhookEventType) UnmarshalText(text []byte) error { - *w = WebhookEventType(text) - if !w.IsValid() { - return fmt.Errorf("%s is not a valid WebhookEventType", string(text)) +func (v WebhookEventType) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *WebhookEventType) UnmarshalText(text []byte) error { + val := WebhookEventType(text) + if !val.IsValid() { + return fmt.Errorf("invalid WebhookEventType value: %q", string(text)) } + *v = val + return nil } -func (w *WebhookEventType) Scan(value any) error { - var s string - - switch v := value.(type) { - case string: - s = v - case []byte: - s = string(v) - default: - return fmt.Errorf("unsupported type for WebhookEventType: %T", value) - } - - return w.UnmarshalText([]byte(s)) -} - -func (w WebhookEventType) Value() (driver.Value, error) { - return w.String(), nil -} - type WebhookEventTypes []WebhookEventType func (s *WebhookEventTypes) Scan(value any) error { @@ -116,7 +113,7 @@ func (s *WebhookEventTypes) scanFromString(str string) error { } var et WebhookEventType - if err := et.Scan(part); err != nil { + if err := et.UnmarshalText([]byte(part)); err != nil { return fmt.Errorf("invalid webhook event type in array: %s", part) } diff --git a/pkg/coredata/webhook_subscription_order_field.go b/pkg/coredata/webhook_subscription_order_field.go index 6c6c62f47..d4d46a534 100644 --- a/pkg/coredata/webhook_subscription_order_field.go +++ b/pkg/coredata/webhook_subscription_order_field.go @@ -15,7 +15,10 @@ package coredata import ( + "encoding" "fmt" + + "go.probo.inc/probo/pkg/page" ) type ( @@ -26,32 +29,48 @@ const ( WebhookSubscriptionOrderFieldCreatedAt WebhookSubscriptionOrderField = "CREATED_AT" ) -func (p WebhookSubscriptionOrderField) Column() string { - return string(p) +var ( + _ page.OrderField = WebhookSubscriptionOrderField("") + _ fmt.Stringer = WebhookSubscriptionOrderField("") + _ encoding.TextMarshaler = WebhookSubscriptionOrderField("") + _ encoding.TextUnmarshaler = (*WebhookSubscriptionOrderField)(nil) +) + +func WebhookSubscriptionOrderFields() []WebhookSubscriptionOrderField { + return []WebhookSubscriptionOrderField{ + WebhookSubscriptionOrderFieldCreatedAt, + } } -func (p WebhookSubscriptionOrderField) String() string { - return string(p) -} - -func (p WebhookSubscriptionOrderField) IsValid() bool { - switch p { - case WebhookSubscriptionOrderFieldCreatedAt: +func (v WebhookSubscriptionOrderField) IsValid() bool { + switch v { + case + WebhookSubscriptionOrderFieldCreatedAt: return true } return false } -func (p WebhookSubscriptionOrderField) MarshalText() ([]byte, error) { - return []byte(p.String()), nil +func (v WebhookSubscriptionOrderField) String() string { + return string(v) } -func (p *WebhookSubscriptionOrderField) UnmarshalText(text []byte) error { - *p = WebhookSubscriptionOrderField(text) - if !p.IsValid() { - return fmt.Errorf("%s is not a valid WebhookSubscriptionOrderField", string(text)) +func (v WebhookSubscriptionOrderField) MarshalText() ([]byte, error) { + return []byte(v.String()), nil +} + +func (v *WebhookSubscriptionOrderField) UnmarshalText(text []byte) error { + val := WebhookSubscriptionOrderField(text) + if !val.IsValid() { + return fmt.Errorf("invalid WebhookSubscriptionOrderField value: %q", string(text)) } + *v = val + return nil } + +func (p WebhookSubscriptionOrderField) Column() string { + return string(p) +} diff --git a/pkg/geoloc/service.go b/pkg/geoloc/service.go index fa1f3839f..59680f065 100644 --- a/pkg/geoloc/service.go +++ b/pkg/geoloc/service.go @@ -54,7 +54,7 @@ func (s *Service) ImportFromDir(ctx context.Context, dataDir string) error { code := strings.ToUpper(entry.Name()) var cc coredata.CountryCode - if err := cc.Scan(code); err != nil { + if err := cc.UnmarshalText([]byte(code)); err != nil { continue } diff --git a/pkg/proboctl/seed/common-third-parties/common_third_parties.go b/pkg/proboctl/seed/common-third-parties/common_third_parties.go index fb52ad5b7..44c3f8303 100644 --- a/pkg/proboctl/seed/common-third-parties/common_third_parties.go +++ b/pkg/proboctl/seed/common-third-parties/common_third_parties.go @@ -181,7 +181,7 @@ func parseCategory(errOut io.Writer, tp thirdPartyData) coredata.ThirdPartyCateg } var c coredata.ThirdPartyCategory - if err := c.Scan(*tp.Category); err != nil { + if err := c.UnmarshalText([]byte(*tp.Category)); err != nil { _, _ = fmt.Fprintf(errOut, "warning: third party %q has unknown category %q, falling back to OTHER\n", tp.Name, *tp.Category) return coredata.ThirdPartyCategoryOther } diff --git a/pkg/server/api/console/v1/resolver.go b/pkg/server/api/console/v1/resolver.go index 7f7cbab9d..8c7ad8974 100644 --- a/pkg/server/api/console/v1/resolver.go +++ b/pkg/server/api/console/v1/resolver.go @@ -153,7 +153,7 @@ func handleConnectorComplete( } var connectorProvider coredata.ConnectorProvider - if err := connectorProvider.Scan(provider); err != nil { + if err := connectorProvider.UnmarshalText([]byte(provider)); err != nil { httpserver.RenderError(w, http.StatusBadRequest, fmt.Errorf("unsupported provider: %q", provider)) return } diff --git a/pkg/server/api/trust/v1/auth_resolvers.go b/pkg/server/api/trust/v1/auth_resolvers.go index 030b743f4..ab94d637d 100644 --- a/pkg/server/api/trust/v1/auth_resolvers.go +++ b/pkg/server/api/trust/v1/auth_resolvers.go @@ -7,8 +7,8 @@ package trust_v1 import ( "context" - "errors" + "go.gearno.de/kit/log" "go.probo.inc/probo/pkg/baseurl" "go.probo.inc/probo/pkg/coredata"