package enmasse.controller.api.osb.v2.catalog;

import java.util.ArrayList;
import java.util.List;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import enmasse.controller.address.AddressManager;
import enmasse.controller.api.osb.v2.OSBServiceBase;
import enmasse.controller.api.osb.v2.ServiceType;
import enmasse.controller.flavor.FlavorRepository;
import enmasse.controller.instance.InstanceManager;

@Path("/v2/catalog")
@Produces({MediaType.APPLICATION_JSON})
public class OSBCatalogService extends OSBServiceBase {

    public OSBCatalogService(InstanceManager instanceManager, AddressManager addressManager, FlavorRepository repository) {
        super(instanceManager, addressManager, repository);
    }

    @GET
    public Response getCatalog() {
        log.info("Received catalog request");
        List<Service> services = new ArrayList<>(4);
        addService(services, ServiceType.ANYCAST, "direct-anycast-network", "Enmasse Anycast", "A brokerless network for direct anycast messaging");
        addService(services, ServiceType.MULTICAST, "direct-multicast-network", "Enmasse Multicast", "A brokerless network for direct multicast messaging");
        addService(services, ServiceType.QUEUE, "queue", "Enmasse Queue", "A messaging queue");
        addService(services, ServiceType.TOPIC, "topic", "Enmasse Topic", "A messaging topic");
        log.info("Returning {} services", services.size());
        return Response.ok(new CatalogResponse(services)).build();
    }

    private void addService(List<Service> services, ServiceType serviceType, String name, String displayName, String description) {
        List<Plan> plans = getPlans(serviceType);
        if (!plans.isEmpty()) {
            Service queueService = new Service(serviceType.uuid(), name, description, true);
            queueService.getPlans().addAll(plans);
            queueService.getTags().add("middleware");
            queueService.getTags().add("amq");
            queueService.getTags().add("messaging");
            queueService.getTags().add("enmasse");
            queueService.getMetadata().put("displayName", displayName);
            queueService.getMetadata().put("providerDisplayName", "Enmasse");
            queueService.getMetadata().put("longDescription", "Long description of " + description + " (TODO)");
            queueService.getMetadata().put("console.openshift.io/iconClass", "fa fa-exchange");
            services.add(queueService);
        }
    }

}

@@ -1004,22 +1004,23 @@
 T, %22
-direct
+enmasse
 -anycast
 -net
@@ -1011,32 +1011,24 @@
 asse-anycast
--network
 %22, %22Enmasse 
@@ -1144,22 +1144,23 @@
 ICAST, %22
-direct
+enmasse
 -multica
@@ -1165,16 +1165,8 @@
 cast
--network
 %22, %22
@@ -1290,16 +1290,24 @@
 QUEUE, %22
+enmasse-
 queue%22, 
@@ -1394,16 +1394,24 @@
 TOPIC, %22
+enmasse-
 topic%22, 

Rename service classes to enmasse-anycast, enmasse-multicast, enmasse-queue and enmasse-topic