/*
* Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/)
*
* 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 eu.teraflow.policy.context.model;

import java.util.List;
import java.util.stream.Collectors;

public class Service {

    private final ServiceId serviceId;
    private final ServiceTypeEnum serviceType;
    private final List<EndPointId> serviceEndPointIds;
    private final List<Constraint> serviceConstraints;
    private final ServiceStatus serviceStatus;
    private final ServiceConfig serviceConfig;

    public Service(
            ServiceId serviceId,
            ServiceTypeEnum serviceType,
            List<EndPointId> serviceEndPointIds,
            List<Constraint> serviceConstraints,
            ServiceStatus serviceStatus,
            ServiceConfig serviceConfig) {
        this.serviceId = serviceId;
        this.serviceType = serviceType;
        this.serviceEndPointIds = serviceEndPointIds;
        this.serviceConstraints = serviceConstraints;
        this.serviceStatus = serviceStatus;
        this.serviceConfig = serviceConfig;
    }

    public ServiceId getServiceId() {
        return serviceId;
    }

    public ServiceTypeEnum getServiceType() {
        return serviceType;
    }

    public List<EndPointId> getServiceEndPointIds() {
        return serviceEndPointIds;
    }

    public List<Constraint> getServiceConstraints() {
        return serviceConstraints;
    }

    public ServiceStatus getServiceStatus() {
        return serviceStatus;
    }

    public ServiceConfig getServiceConfig() {
        return serviceConfig;
    }

    @Override
    public String toString() {
        return String.format(
                "%s:{%s, serviceType:\"%s\", [%s], [%s], %s, %s}",
                getClass().getSimpleName(),
                serviceId,
                serviceType.toString(),
                toString(serviceEndPointIds),
                toString(serviceConstraints),
                serviceStatus,
                serviceConfig);
    }

    private <T> String toString(List<T> list) {
        return list.stream().map(T::toString).collect(Collectors.joining(", "));
    }
}
