/**
  * @param Document $document
  * @param array $options
  * @return array
  */
 protected function buildRequestOptions($options, Document $document = null)
 {
     $requestOptions = ['headers' => []];
     if (isset($document)) {
         $requestOptions['json'] = $document->getData();
     } elseif (isset($options['getAuthToken'])) {
         $requestOptions['json'] = $options['getAuthToken'];
     } elseif (isset($options['json'])) {
         $requestOptions['json'] = $options['json'];
     }
     if (isset($options['headers'])) {
         $requestOptions['headers'] += $options['headers'];
     }
     if (isset($options['setAuthToken'])) {
         $requestOptions['headers'] += ['X-CouchDB-WWW-Authenticate' => 'Cookie'];
         $requestOptions['cookies'] = $this->buildAuthCookie($options['setAuthToken']);
     }
     if (isset($options['user'])) {
         $requestOptions['auth'] = [$options['user']['username'], $options['user']['password']];
     }
     if ($this->debug) {
         $requestOptions['debug'] = true;
     }
     return $requestOptions;
 }
 /**
  * Deletes the document. CouchDB will still retain a copy though
  * @param Document $document
  * @throws BadMethodCallException
  */
 public function deleteDocument(Document $document)
 {
     $data = $document->getData();
     if (!isset($data['_id'])) {
         throw new BadMethodCallException("Cannot delete document without an ID");
     }
     if (!isset($data['_rev'])) {
         throw new BadMethodCallException("Cannot delete document without a revision number");
     }
     $this->client->delete($this->getDocumentUrl($data['_id'], array('rev' => $data['_rev'])), 200, $this->server->getOptions());
     $document->unsetRev();
 }