diff --git a/src/Socialbox/Objects/Database/ContactRecord.php b/src/Socialbox/Objects/Database/ContactRecord.php new file mode 100644 index 0000000..3900920 --- /dev/null +++ b/src/Socialbox/Objects/Database/ContactRecord.php @@ -0,0 +1,138 @@ +uuid = $data['uuid']; + $this->peerUuid = $data['peer_uuid']; + $this->contactPeerAddress = $data['contact_peer_address']; + + if(is_string($data['relationship'])) + { + $this->relationship = ContactRelationshipType::from($data['relationship']); + } + elseif($data['relationship'] instanceof ContactRelationshipType) + { + $this->relationship = $data['relationship']; + } + else + { + throw new InvalidArgumentException('Invalid relationship type'); + } + + if(is_int($data['created'])) + { + $this->created = (new DateTime())->setTimestamp($data['created']); + } + elseif(is_string($data['created'])) + { + $this->created = new DateTime($data['created']); + } + elseif($data['created'] instanceof DateTime) + { + $this->created = $data['created']; + } + else + { + throw new InvalidArgumentException('Invalid created date'); + } + } + + /** + * + * @return string Returns the UUID as a string. + */ + public function getUuid(): string + { + return $this->uuid; + } + + /** + * Retrieves the UUID of the peer. + * + * @return string The UUID of the peer. + */ + public function getPeerUuid(): string + { + return $this->peerUuid; + } + + /** + * Retrieves the contact peer address. + * + * @return string The contact peer address. + */ + public function getContactPeerAddress(): string + { + return $this->contactPeerAddress; + } + + /** + * Retrieves the relationship type of the contact. + * + * @return ContactRelationshipType The relationship type of the contact. + */ + public function getRelationship(): ContactRelationshipType + { + return $this->relationship; + } + + /** + * Retrieves the created date and time. + * + * @return DateTime The DateTime object representing when the entity was created. + */ + public function getCreated(): DateTime + { + return $this->created; + } + + /** + * @inheritDoc + */ + public static function fromArray(array $data): ContactRecord + { + return new self($data); + } + + /** + * @inheritDoc + */ + public function toArray(): array + { + return [ + 'uuid' => $this->uuid, + 'peer_uuid' => $this->peerUuid, + 'contact_peer_address' => $this->contactPeerAddress, + 'relationship' => $this->relationship->value, + 'created' => $this->created->format('Y-m-d H:i:s') + ]; + } + } \ No newline at end of file