/*
 * Copyright 2013 Red Hat, Inc. and/or its affiliates.
 *
 * 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 org.kie.config.cli;

import java.util.Collections;
import java.util.List;
import java.util.Set;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Produces;
import javax.inject.Inject;
import javax.inject.Named;

import org.jboss.errai.security.shared.api.identity.User;
import org.jboss.errai.security.shared.service.AuthenticationService;
import org.kie.workbench.common.services.refactoring.model.index.terms.IndexTerm;
import org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueIndexTerm;
import org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRequest;
import org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRow;
import org.kie.workbench.common.services.refactoring.service.RefactoringQueryService;
import org.uberfire.io.IOService;
import org.uberfire.io.impl.IOServiceDotFileImpl;
import org.uberfire.paging.PageResponse;
import org.uberfire.rpc.SessionInfo;
import org.uberfire.rpc.impl.SessionInfoImpl;

@ApplicationScoped
public class EnvironmentProvider {

    private final IOService ioService = new IOServiceDotFileImpl();

    @Inject
    CliIdentity cliIdentity;

    @Produces
    @Named("ioStrategy")
    public IOService ioService() {
        return ioService;
    }

    @Produces
    public SessionInfo getSessionInfo() {
        return new SessionInfoImpl( cliIdentity.getIdentifier(), cliIdentity );
    }

    @Produces
    public RefactoringQueryService getRefactoringQueryService() {
        return new RefactoringQueryService() {
            @Override
            public Set<String> getQueries() {
                return Collections.emptySet();
            }

            @Override
            public Set<IndexTerm> getTerms( String queryName ) {
                return Collections.emptySet();
            }

            @Override
            public PageResponse<RefactoringPageRow> query( RefactoringPageRequest request ) {
                return new PageResponse<RefactoringPageRow>();
            }

            @Override
            public List<RefactoringPageRow> query( String queryName,
                                                   Set<ValueIndexTerm> queryTerms,
                                                   boolean useWildcards ) {
                return Collections.emptyList();
            }
        };
    }

    @Produces
    public AuthenticationService getAuthenticationService() {
        return new AuthenticationService() {
            @Override
            public User login( String s,
                               String s2 ) {
                return cliIdentity;
            }

            @Override
            public boolean isLoggedIn() {
                return false;
            }

            @Override
            public void logout() {
            }

            @Override
            public User getUser() {
                return cliIdentity;
            }
        };
    }

}

@@ -1426,32 +1426,123 @@
 ngQueryService;%0A
+import org.kie.workbench.common.services.refactoring.service.impact.QueryOperationRequest;%0A
 import org.uberf
@@ -2156,32 +2156,66 @@
 %0A%0A    @Produces%0A
+    @SuppressWarnings(%22rawtypes%22)%0A
     public Refac
@@ -2303,32 +2303,33 @@
 ueryService() %7B%0A
+%0A
             @Ove
@@ -2357,179 +2357,333 @@
 lic 
-Set%3CString%3E getQueries() %7B%0A                return Collections.emptySet();%0A            %7D%0A%0A            @Override%0A            public Set%3CIndexTerm%3E getTerms( String queryName
+PageResponse%3CRefactoringPageRow%3E query( RefactoringPageRequest request ) %7B%0A                return new PageResponse%3CRefactoringPageRow%3E();%0A            %7D%0A%0A            @Override%0A            public List%3CRefactoringPageRow%3E query( String queryName,%0A                                                   Set%3CValueIndexTerm%3E queryTerms
  ) %7B
@@ -2723,18 +2723,19 @@
 ns.empty
-Se
+Lis
 t();%0A   
@@ -2825,33 +2825,46 @@
 w%3E query
-( RefactoringPage
+ToPageResponse( QueryOperation
 Request 
@@ -3028,182 +3028,45 @@
 uery
-( String queryName,%0A                                                   Set%3CValueIndexTerm%3E queryTerms,%0A                                                   boolean useWildcards
+ToList( QueryOperationRequest request
  ) %7B

fix build after RefactoringQueryService changes (#330)