github.com/alloyzeus/go-azfl@v0.0.0-20231220071816-9740126a2d07/azcore/entity.go (about) 1 package azcore 2 3 import "github.com/alloyzeus/go-azfl/azid" 4 5 // Entity defines the contract for all its concrete implementations. 6 // 7 // For now, this is unused. 8 type Entity interface { 9 AZEntity() 10 } 11 12 // An EntityID is an identifier of an entity. 13 type EntityID[IDNumT EntityIDNum] interface { 14 azid.ID[IDNumT] 15 16 AZEntityID() 17 } 18 19 // An EntityAttributes instance contains the actual attributes of an entity. 20 // It's on itself is a value object and does not have any identity. 21 // 22 // An EntityAttributes instance doesn't hold the ID of its entity instance. 23 // For the structure that holds both the ID and its attributes, see 24 // KeyedEntityAttributes, which pratically contains a pair of attributes -- 25 // the ID of the entity and the of attributes of the entity. 26 type EntityAttributes interface { 27 Attributes 28 29 AZEntityAttributes() 30 } 31 32 // KeyedEntityAttributes is a self-identifying data structure that contains 33 // both the ID of the entity and its representing attributes. 34 // 35 //TODO: an envelope with EntityInstanceInfo? 36 type KeyedEntityAttributes[ 37 EntityIDNumT EntityIDNum, 38 EntityIDT EntityID[EntityIDNumT], 39 EntityAttributesT EntityAttributes, 40 ] struct { 41 ID EntityIDT 42 Attributes EntityAttributesT 43 } 44 45 type EntityIDNumMethods interface { 46 AZEntityIDNum() 47 } 48 49 // EntityIDNum is the unique or local part of an entity identifier. 50 // 51 //TODO: this is a value-object. 52 type EntityIDNum interface { 53 azid.IDNum 54 55 EntityIDNumMethods 56 } 57 58 // EntityInstanceInfo holds information about an instance of entity, i.e., 59 // metadata of an instance of entity. It doesn't contain the attributes of 60 // the instance itself. 61 type EntityInstanceInfo[ 62 RevisionNumberT EntityRevisionNumber, 63 DeletionInfoT EntityDeletionInfo, 64 ] interface { 65 RevisionNumber() RevisionNumberT 66 67 // Deletion returns a detailed information about the deletion if 68 // the instance has been deleted. 69 Deletion() *DeletionInfoT 70 // IsDeleted returns true if the instance has been deleted. 71 IsDeleted() bool 72 } 73 74 // EntityInstanceInfoBase is a base implementation of EntityInstanceInfo with 75 // all attributes are public. 76 type EntityInstanceInfoBase[ 77 RevisionNumberT EntityRevisionNumber, 78 DeletionInfoT EntityDeletionInfo, 79 ] struct { 80 RevisionNumber_ RevisionNumberT 81 Deletion_ *DeletionInfoT 82 } 83 84 var _ EntityInstanceInfo[ 85 int32, EntityDeletionInfoBase, 86 ] = EntityInstanceInfoBase[int32, EntityDeletionInfoBase]{} 87 88 func (instanceInfo EntityInstanceInfoBase[ 89 RevisionNumberT, DeletionInfoT, 90 ]) RevisionNumber() RevisionNumberT { 91 return instanceInfo.RevisionNumber_ 92 } 93 94 func (instanceInfo EntityInstanceInfoBase[ 95 RevisionNumberT, DeletionInfoT, 96 ]) Deletion() *DeletionInfoT { 97 return instanceInfo.Deletion_ 98 } 99 100 func (instanceInfo EntityInstanceInfoBase[ 101 RevisionNumberT, DeletionInfoT, 102 ]) IsDeleted() bool { 103 if delInfo := instanceInfo.Deletion_; delInfo != nil { 104 return (*delInfo).Deleted() 105 } 106 return false 107 } 108 109 type EntityRevisionNumber interface { 110 int16 | int32 | int64 111 }