<?php
 namespace MongoDB\Operation;
 use MongoDB\Driver\Command;
 use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
 use MongoDB\Driver\Server;
 use MongoDB\Driver\Session;
 use MongoDB\Driver\WriteConcern;
 use MongoDB\Exception\InvalidArgumentException;
 use MongoDB\Exception\UnsupportedException;
 use function current;
 use function is_array;
 use function is_integer;
 use function MongoDB\server_supports_feature;
 class DropIndexes implements Executable {
 private static $wireVersionForWriteConcern = 5;
 private $databaseName;
 private $collectionName;
 private $indexName;
 private $options;
 public function __construct($databaseName, $collectionName, $indexName, array $options = []) {
 $indexName = (string) $indexName;
 if ($indexName === '') {
 throw new InvalidArgumentException('$indexName cannot be empty');
 }
 if (isset($options['maxTimeMS']) && ! is_integer($options['maxTimeMS'])) {
 throw InvalidArgumentException::invalidType('"maxTimeMS" option', $options['maxTimeMS'], 'integer');
 }
 if (isset($options['session']) && ! $options['session'] instanceof Session) {
 throw InvalidArgumentException::invalidType('"session" option', $options['session'], Session::class);
 }
 if (isset($options['typeMap']) && ! is_array($options['typeMap'])) {
 throw InvalidArgumentException::invalidType('"typeMap" option', $options['typeMap'], 'array');
 }
 if (isset($options['writeConcern']) && ! $options['writeConcern'] instanceof WriteConcern) {
 throw InvalidArgumentException::invalidType('"writeConcern" option', $options['writeConcern'], WriteConcern::class);
 }
 if (isset($options['writeConcern']) && $options['writeConcern']->isDefault()) {
 unset($options['writeConcern']);
 }
 $this->databaseName = (string) $databaseName;
 $this->collectionName = (string) $collectionName;
 $this->indexName = $indexName;
 $this->options = $options;
 }
 public function execute(Server $server) {
 if (isset($this->options['writeConcern']) && ! server_supports_feature($server, self::$wireVersionForWriteConcern)) {
 throw UnsupportedException::writeConcernNotSupported();
 }
 $inTransaction = isset($this->options['session']) && $this->options['session']->isInTransaction();
 if ($inTransaction && isset($this->options['writeConcern'])) {
 throw UnsupportedException::writeConcernNotSupportedInTransaction();
 }
 $cursor = $server->executeWriteCommand($this->databaseName, $this->createCommand(), $this->createOptions());
 if (isset($this->options['typeMap'])) {
 $cursor->setTypeMap($this->options['typeMap']);
 }
 return current($cursor->toArray());
 }
 private function createCommand() {
 $cmd = [ 'dropIndexes' => $this->collectionName, 'index' => $this->indexName, ];
 if (isset($this->options['maxTimeMS'])) {
 $cmd['maxTimeMS'] = $this->options['maxTimeMS'];
 }
 return new Command($cmd);
 }
 private function createOptions() {
 $options = [];
 if (isset($this->options['session'])) {
 $options['session'] = $this->options['session'];
 }
 if (isset($this->options['writeConcern'])) {
 $options['writeConcern'] = $this->options['writeConcern'];
 }
 return $options;
 }
 }
 