

package org.cloudfoundry.uaa.clients;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
import org.immutables.value.Value;

import java.io.IOException;
import java.util.List;

/**
 * The response from the Batch Delete Clients request
 */
@JsonDeserialize(using = _BatchDeleteClientsResponse.BatchDeleteClientsResponseDeserializer.class)
@Value.Immutable
abstract class _BatchDeleteClientsResponse {

    /**
     * The deleted clients
     */
    abstract List<Client> getClients();

    static class BatchDeleteClientsResponseDeserializer extends StdDeserializer<BatchDeleteClientsResponse> {

        private static final long serialVersionUID = 999593607348906876L;

        BatchDeleteClientsResponseDeserializer() {
            super(BatchDeleteClientsResponse.class);
        }

        @Override
        @SuppressWarnings("unchecked")
        public BatchDeleteClientsResponse deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
            return BatchDeleteClientsResponse.builder()
                .clients((List<Client>) p.readValueAs(new TypeReference<List<Client>>() {

                }))
                .build();
        }
    }

}
