public function toArray()
{
$this->checkRecipient();
if (is_null($this->attachment_type)) {
throw CouldNotCreateMessage::noAttachmentType();
}
if (is_null($this->attachment_url) && is_null($this->attachment_id)) {
throw CouldNotCreateMessage::noAttachmentUrl();
}
$payload = ['url' => $this->attachment_url];
if ($this->is_reuseable) {
$payload['is_reuseable'] = true;
}
if (!is_null($this->attachment_id)) {
$payload = ['attachment_id' => $this->attachment_id];
}
return ['recipient' => ['id' => $this->recipient_id], 'message' => ['attachment' => ['type' => $this->attachment_type, 'payload' => $payload]]];
}