         return self
     }
     
-    public func build() -> CreateIndexRequest {
+    public func set(settings: [String: CodableValue]) -> Self {
+        self.settings = settings
+        return self
+    }
+    
+    public func set(mappings: [String: MappingMetaData]) -> Self {
+        self.mappings = mappings
+        return self
+    }
+    
+    public func set(aliases: [IndexAlias]) -> Self {
+        self.aliases = aliases
+        return self
+    }
+    
+    public func build() throws -> CreateIndexRequest {
+        
+        guard self.name != nil else {
+            throw RequestBuilderError.missingRequiredField("name")
+        }
+        
         return CreateIndexRequest(withBuilder: self)
     }
 }


//MARK:- Create Index Reqeust

public class CreateIndexRequest: Request {
    public var headers: HTTPHeaders = HTTPHeaders()
    
    public var queryParams: [URLQueryItem] = []
    
    public typealias ResponseType = CreateIndexResponse
    
    public let name: String
    
    public init(name: String) {
        self.name = name
    }
    
    init(withBuilder builder: CreateIndexRequestBuilder) {
        self.name = builder.name!
    }
    
    public var method: HTTPMethod {

        }
    }
    
    public var queryParams: [URLQueryItem] {
        get {
            var params = [URLQueryItem]()
            if let includeTypeName = self.includeTypeName {
                params.append(URLQueryItem(name: QueryParams.includeTypeName.rawValue, value: "\(includeTypeName)"))
            }
            return params
        }
    }
    
    public func makeBody(_ serializer: Serializer) -> Result<Data, MakeBodyError> {
        guard self.aliases != nil || self.mappings != nil || self.settings != nil else {
            return .failure(.noBodyForRequest)
        }
        return serializer.encode(self).mapError {
            error -> MakeBodyError in
            return .wrapped(error)
        }
    }
    
    public func encode(to encoder: Encoder) throws {
        var container = encoder.container(keyedBy: CodingKeys.self)
        try container.encodeIfPresent(self.mappings, forKey: .mappings)
        try container.encodeIfPresent(self.settings, forKey: .settings)
        if let aliases = self.aliases {
            let dic = Dictionary(uniqueKeysWithValues: aliases.map{ ($0.name, $0.metaData)})
            try container.encode(dic, forKey: .aliases)
        }
    }
    
    enum CodingKeys: CodingKey {
        case aliases
        case mappings
        case settings
    }
}

