-
Notifications
You must be signed in to change notification settings - Fork 20
/
field.go
72 lines (59 loc) · 1.58 KB
/
field.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package assets
import (
"fmt"
"github.com/nyaruka/gocommon/uuids"
)
// FieldUUID is the UUID of a field
type FieldUUID uuids.UUID
// FieldType is the data type of values for each field
type FieldType string
// field value types
const (
FieldTypeText FieldType = "text"
FieldTypeNumber FieldType = "number"
FieldTypeDatetime FieldType = "datetime"
FieldTypeWard FieldType = "ward"
FieldTypeDistrict FieldType = "district"
FieldTypeState FieldType = "state"
)
// Field is a custom contact property.
//
// {
// "uuid": "d66a7823-eada-40e5-9a3a-57239d4690bf",
// "key": "gender",
// "name": "Gender",
// "type": "text"
// }
//
// @asset field
type Field interface {
UUID() FieldUUID
Key() string
Name() string
Type() FieldType
}
// FieldReference is a reference to a field
type FieldReference struct {
Key string `json:"key" validate:"required"`
Name string `json:"name"`
}
// NewFieldReference creates a new field reference with the given key and name
func NewFieldReference(key string, name string) *FieldReference {
return &FieldReference{Key: key, Name: name}
}
// Type returns the name of the asset type
func (r *FieldReference) Type() string {
return "field"
}
// Identity returns the unique identity of the asset
func (r *FieldReference) Identity() string {
return string(r.Key)
}
// Variable returns whether this a variable (vs concrete) reference
func (r *FieldReference) Variable() bool {
return false
}
func (r *FieldReference) String() string {
return fmt.Sprintf("%s[key=%s,name=%s]", r.Type(), r.Identity(), r.Name)
}
var _ Reference = (*FieldReference)(nil)