/*
 *
 *   Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
 *
 *   WSO2 Inc. licenses this file to you 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 org.wso2.carbon.apimgt.core.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.wso2.carbon.apimgt.core.api.APIStore;
import org.wso2.carbon.apimgt.core.dao.APISubscriptionDAO;
import org.wso2.carbon.apimgt.core.dao.ApiDAO;
import org.wso2.carbon.apimgt.core.dao.ApplicationDAO;
import org.wso2.carbon.apimgt.core.exception.APIManagementException;
import org.wso2.carbon.apimgt.core.models.APIResults;
import org.wso2.carbon.apimgt.core.models.Application;
import org.wso2.carbon.apimgt.core.models.Subscriber;
import org.wso2.carbon.apimgt.core.util.APIUtils;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * Implementation of API Store operations.
 *
 */
public class APIStoreImpl extends AbstractAPIManager implements APIStore {

    private static final Logger log = LoggerFactory.getLogger(APIStoreImpl.class);

    public APIStoreImpl(String username, ApiDAO apiDAO, ApplicationDAO applicationDAO,
            APISubscriptionDAO apiSubscriptionDAO) {
        super(username, apiDAO, applicationDAO, apiSubscriptionDAO, new APILifeCycleManagerImpl());
    }

    @Override
    public APIResults getAllAPIsByStatus(int offset, int limit, String[] statuses)
            throws APIManagementException {
        APIResults apiResults = null;
        try {
            apiResults = getApiDAO().getAPIsByStatus(offset, limit, new ArrayList<String>(Arrays.asList(statuses)));
        } catch (SQLException e) {
            APIUtils.logAndThrowException("Error occurred while fetching APIs for the given statuses - " + Arrays.toString(statuses), e,
                    log);
        }
        return apiResults;
    }

    @Override
    public Application getApplicationsByName(String userId, String applicationName, String groupId)
            throws APIManagementException {
        Application application = null;
        try {
            application = getApplicationDAO().getApplicationByName(userId, applicationName, groupId);
        } catch (SQLException e) {
            APIUtils.logAndThrowException(
                    "Error occurred while fetching application for the given applicationName - " + applicationName  + " with groupId - " + groupId, e,
                    log);
        }
        return application;
    }

    @Override
    public Application[] getApplications(Subscriber subscriber, String groupId) throws APIManagementException {
        Application[] applicationList = null;
        try {
            applicationList = getApplicationDAO().getApplications(subscriber, groupId);
        } catch (SQLException e) {
            APIUtils.logAndThrowException(
                    "Error occurred while fetching applications for the given subscriber - " + subscriber.getName()
                            + " with groupId - " + groupId, e, log);
        }
        return applicationList;
    }

    @Override
    public void updateApplication(Application application) throws APIManagementException {

    }

    @Override
    public Map<String, Object> requestApprovalForApplicationRegistration(String userId, String applicationName,
            String tokenType, String callbackUrl, String[] allowedDomains, String validityTime, String tokenScope,
            String groupingId, String jsonString) throws APIManagementException {
        return null;
    }

    @Override
    public boolean isApplicationExists(String appName, String username, String groupId)
            throws APIManagementException {
        boolean isApplicationExists = false;
        try {
            isApplicationExists = getApplicationDAO().isApplicationExists(appName, username, groupId);
        } catch (SQLException e) {
            APIUtils.logAndThrowException(
                    "Error occurred while checking whether application exists for applicationName- " + appName + " with groupId - " + groupId, e, log);
        }
        return isApplicationExists;
    }

    public APIResults searchAPIs(String query, int offset, int limit)
            throws APIManagementException {

        APIResults apiResults = null;
        try {
            List<String> roles = new ArrayList<>(); // TODO -- roles list
            apiResults = getApiDAO().searchAPIsForRoles(query, offset, limit,
                    roles);
        } catch (SQLException e) {
            APIUtils.logAndThrowException("Error occurred while updating searching APIs - " + query, e, log);
        }

        return apiResults;
    }

    @Override
    public Application getApplicationByUUID(String uuid) throws APIManagementException {
        return null;
    }

    @Override
    public void removeApplication(Application application) throws APIManagementException {

    }

    @Override
    public String addApplication(Application application, String userId) throws APIManagementException {
        return null;
    }

  }

@@ -5222,139 +5222,8 @@
  %7D%0A%0A
-    @Override%0A    public Application getApplicationByUUID(String uuid) throws APIManagementException %7B%0A        return null;%0A    %7D%0A%0A
     

remove wrong override