public function createAttachmentEntity(EntityInterface $entity, $filePath, array $tags = [])
    {
        if (!file_exists($filePath)) {
            throw new \Exception("File {$filePath} does not exist.");
        }
        if (!is_readable($filePath)) {
            throw new \Exception("File {$filePath} cannot be read.");
        }
        $file = new File($filePath);
        $info = $file->info();

        // in filepath, we store the path relative to the Attachment.path configuration
        // to make it easy to switch storage
        $info = $this->__getFileName($info, $entity);
        $targetPath = $entity->source() . '/' . $entity->id . '/' . $info['basename'];

        $attachment = $this->newEntity([
            'model' => $entity->source(),
            'foreign_key' => $entity->id,
            'filename' => $info['basename'],
            'filesize' => $info['filesize'],
            'filetype' => $info['mime'],
            'filepath' => $targetPath,
            'tmpPath' => $filePath,
            'tags' => $tags
        ]);
        return $attachment;
    }