// Path: src/main/java/com/tango/BucketSyncer/ObjectSummaries/GCS_ObjectSummary.java
// public class GCS_ObjectSummary implements ObjectSummary {
//     StorageObject storageObject;
// 
//     public GCS_ObjectSummary(StorageObject storageObject) {
//         this.storageObject = storageObject;
//     }
// 
//     @Override
//     public String getKey() {
//         return storageObject.getName();
//     }
// 
//     @Override
//     public long getSize() {
//         return storageObject.getSize().longValue();
//     }
// 
//     @Override
//     public Date getLastModified() {
//         return new Date(storageObject.getUpdated().getValue());
//     }
// 
//     @Override
//     public String getETag() {
//         return storageObject.getEtag();
//     }
// }
// 
// Path: src/main/java/com/tango/BucketSyncer/ObjectSummaries/ObjectSummary.java
// public interface ObjectSummary {
//     public String getKey();
// 
//     public long getSize();
// 
//     public Date getLastModified();
// 
//     public String getETag();
// }


import com.google.api.services.storage.Storage;
import com.google.api.services.storage.model.Objects;
import com.google.api.services.storage.model.StorageObject;
import com.tango.BucketSyncer.*;
import com.tango.BucketSyncer.ObjectSummaries.GCS_ObjectSummary;
import com.tango.BucketSyncer.ObjectSummaries.ObjectSummary;
import lombok.extern.slf4j.Slf4j;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
/**
 *  Copyright 2014 TangoMe Inc.
 *
 *  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 com.tango.BucketSyncer.KeyListers;



@Slf4j
public class GCSKeyLister extends KeyLister {
    private Storage gcsClient;
    private final List<ObjectSummary> summaries;
    private Objects objects;


    public GCSKeyLister(Object client,
                        String bucket,
                        String prefix,
                        MirrorContext context,
                        Integer maxQueueCapacity) {
        super(bucket, prefix, context, maxQueueCapacity);
        this.gcsClient = (Storage) client;
        final MirrorOptions options = context.getOptions();
        int fetchSize = options.getMaxThreads();
        this.summaries = new ArrayList<ObjectSummary>(10 * fetchSize);

        objects = gcsGetFirstBatch(bucket, prefix, Long.valueOf(fetchSize));
        synchronized (summaries) {

            for (StorageObject object : objects.getItems()) {
                // Add to object summaries
// Path: src/main/java/com/tango/BucketSyncer/ObjectSummaries/GCS_ObjectSummary.java
// public class GCS_ObjectSummary implements ObjectSummary {
//     StorageObject storageObject;
// 
//     public GCS_ObjectSummary(StorageObject storageObject) {
//         this.storageObject = storageObject;
//     }
// 
//     @Override
//     public String getKey() {
//         return storageObject.getName();
//     }
// 
//     @Override
//     public long getSize() {
//         return storageObject.getSize().longValue();
//     }
// 
//     @Override
//     public Date getLastModified() {
//         return new Date(storageObject.getUpdated().getValue());
//     }
// 
//     @Override
//     public String getETag() {
//         return storageObject.getEtag();
//     }
// }
// 
// Path: src/main/java/com/tango/BucketSyncer/ObjectSummaries/ObjectSummary.java
// public interface ObjectSummary {
//     public String getKey();
// 
//     public long getSize();
// 
//     public Date getLastModified();
// 
//     public String getETag();
// }


// Path: src/main/java/com/tango/BucketSyncer/KeyListers/GCSKeyLister.java
import com.google.api.services.storage.Storage;
import com.google.api.services.storage.model.Objects;
import com.google.api.services.storage.model.StorageObject;
import com.tango.BucketSyncer.*;
import com.tango.BucketSyncer.ObjectSummaries.GCS_ObjectSummary;
import com.tango.BucketSyncer.ObjectSummaries.ObjectSummary;
import lombok.extern.slf4j.Slf4j;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 *  Copyright 2014 TangoMe Inc.
 *
 *  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 com.tango.BucketSyncer.KeyListers;



@Slf4j
public class GCSKeyLister extends KeyLister {
    private Storage gcsClient;
    private final List<ObjectSummary> summaries;
    private Objects objects;


    public GCSKeyLister(Object client,
                        String bucket,
                        String prefix,
                        MirrorContext context,
                        Integer maxQueueCapacity) {
        super(bucket, prefix, context, maxQueueCapacity);
        this.gcsClient = (Storage) client;
        final MirrorOptions options = context.getOptions();
        int fetchSize = options.getMaxThreads();
        this.summaries = new ArrayList<ObjectSummary>(10 * fetchSize);

        objects = gcsGetFirstBatch(bucket, prefix, Long.valueOf(fetchSize));
        synchronized (summaries) {

            for (StorageObject object : objects.getItems()) {
                // Add to object summaries
                ObjectSummary os = new GCS_ObjectSummary(object);