/*
 *
 *  Copyright 2015 the original author or authors.
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 *
 */

package springfox.documentation.service;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;

import static com.google.common.base.Optional.*;
import static com.google.common.collect.Lists.*;

public class ResourceListing {
  private final String apiVersion;
  private final List<ApiListingReference> apis;
  private final LinkedHashMap<String, SecurityScheme> securitySchemes;
  private final ApiInfo info;

  public ResourceListing(String apiVersion,
                         List<ApiListingReference> apis,
                         List<SecurityScheme> securitySchemes,
                         ApiInfo info) {

    this.apiVersion = apiVersion;
    this.apis = apis;
    this.securitySchemes = initializeSecuritySchemes(securitySchemes);
    this.info = info;
  }

  private LinkedHashMap<String, SecurityScheme> initializeSecuritySchemes(List<SecurityScheme> securitySchemes) {
    LinkedHashMap<String, SecurityScheme> mapped = new LinkedHashMap<String, SecurityScheme>();
    List<SecurityScheme> emptyList = newArrayList();
    for (SecurityScheme securityScheme : fromNullable(securitySchemes).or(emptyList)) {
      mapped.put(securityScheme.getType(), securityScheme);
    }
    return mapped;
  }

  public String getApiVersion() {
    return apiVersion;
  }

  public List<ApiListingReference> getApis() {
    return apis;
  }

  public List<SecurityScheme> getSecuritySchemes() {
    return new ArrayList<SecurityScheme>(securitySchemes.values());
  }

  public ApiInfo getInfo() {
    return info;
  }
}

@@ -694,171 +694,12 @@
 til.
-ArrayList;%0Aimport java.util.LinkedHashMap;%0Aimport java.util.List;%0A%0Aimport static com.google.common.base.Optional.*;%0Aimport static com.google.common.collect.Lists.*
+List
 ;%0A%0Ap
@@ -829,36 +829,19 @@
 final Li
-nkedHashMap%3CString, 
+st%3C
 Security
@@ -1189,34 +1189,8 @@
 s = 
-initializeSecuritySchemes(
 secu
@@ -1200,17 +1200,16 @@
 ySchemes
-)
 ;%0A    th
@@ -1233,449 +1233,8 @@
  %7D%0A%0A
-  private LinkedHashMap%3CString, SecurityScheme%3E initializeSecuritySchemes(List%3CSecurityScheme%3E securitySchemes) %7B%0A    LinkedHashMap%3CString, SecurityScheme%3E mapped = new LinkedHashMap%3CString, SecurityScheme%3E();%0A    List%3CSecurityScheme%3E emptyList = newArrayList();%0A    for (SecurityScheme securityScheme : fromNullable(securitySchemes).or(emptyList)) %7B%0A      mapped.put(securityScheme.getType(), securityScheme);%0A    %7D%0A    return mapped;%0A  %7D%0A%0A
   pu
@@ -1428,38 +1428,8 @@
 urn 
-new ArrayList%3CSecurityScheme%3E(
 secu
@@ -1443,18 +1443,8 @@
 emes
-.values())
 ;%0A  

allow security scheme of same type in resource listing