package de.jeha.s3srv.api;

import de.jeha.s3srv.jaxb.InstantXmlAdapter;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author jenshadlich@googlemail.com
 */
@XmlRootElement(name = "ListAllMyBucketsResponse")
public class ListAllMyBucketsResponse {

    @XmlElement(name = "Owner")
    private Owner owner;

    @XmlElementWrapper(name = "Buckets")
    @XmlElement(name = "Bucket")
    private List<Entry> buckets = new ArrayList<>();

    public ListAllMyBucketsResponse() {
    }

    public ListAllMyBucketsResponse(Owner owner, Entry... entries) {
        this.owner = owner;
        Collections.addAll(buckets, entries);
    }

    public static class Owner {

        @XmlElement(name = "ID")
        private String id;

        @XmlElement(name = "DisplayName")
        private String displayName;

        public Owner(String id, String displayName) {
            this.id = id;
            this.displayName = displayName;
        }

    }

    public static class Entry {

        @XmlElement(name = "Name")
        private String name;

        @XmlElement(name = "CreationDate")
        @XmlJavaTypeAdapter(InstantXmlAdapter.class)
        private Instant creationDate;

        public Entry(String name, Instant creationDate) {
            this.name = name;
            this.creationDate = creationDate;
        }

    }

}

@@ -896,32 +896,172 @@
 ntries);%0A    %7D%0A%0A
+    public ListAllMyBucketsResponse(Owner owner, List%3CEntry%3E entries) %7B%0A        this.owner = owner;%0A        buckets.addAll(entries);%0A    %7D%0A%0A
     public stati

add constructor