// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) AutoRest Code Generator.

package com.azure.communication.jobrouter.models;

import com.azure.communication.jobrouter.implementation.accesshelpers.LabelValueConstructorProxy;
import com.azure.communication.jobrouter.implementation.accesshelpers.RouterWorkerConstructorProxy;
import com.azure.communication.jobrouter.implementation.converters.WorkerAdapter;
import com.azure.communication.jobrouter.implementation.models.RouterWorkerInternal;
import com.azure.core.annotation.Fluent;
import com.fasterxml.jackson.annotation.JsonProperty;

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

/** An entity for jobs to be routed to. */
@Fluent
public final class RouterWorker {
    /**
     * Public constructor.
     *
     * @param id The id
     */
    public RouterWorker(String id) {
        this.id = id;
    }

    /**
     * Package-private constructor of the class, used internally.
     *
     * @param internal The internal RouterWorker
     */
    RouterWorker(RouterWorkerInternal internal) {
        id = internal.getId();
        state = RouterWorkerState.fromString(internal.getState().toString());
        offers = WorkerAdapter.convertOffersToPublic(internal.getOffers());
        assignedJobs = WorkerAdapter.convertAssignmentsToPublic(internal.getAssignedJobs());
        loadRatio = internal.getLoadRatio();

        setLabels(internal.getLabels().entrySet().stream()
            .collect(Collectors.toMap(Map.Entry::getKey, entry -> LabelValueConstructorProxy.create(entry.getValue()))));
        setTags(internal.getTags().entrySet().stream()
            .collect(Collectors.toMap(Map.Entry::getKey, entry -> LabelValueConstructorProxy.create(entry.getValue()))));
        setQueueAssignments(internal.getQueueAssignments().entrySet().stream()
            .collect(Collectors.toMap(Map.Entry::getKey, entry -> new RouterQueueAssignment())));
        setAvailableForOffers(internal.isAvailableForOffers());
        setChannelConfigurations(WorkerAdapter.convertChannelConfigurationsToPublic(internal.getChannelConfigurations()));
        setTotalCapacity(internal.getTotalCapacity());
    }

    static {
        RouterWorkerConstructorProxy.setAccessor(internal -> new RouterWorker(internal));
    }

    /*
     * The id property.
     */
    @JsonProperty(value = "id", access = JsonProperty.Access.WRITE_ONLY)
    private String id;

    /*
     * The current state of the worker.
     */
    @JsonProperty(value = "state", access = JsonProperty.Access.WRITE_ONLY)
    private RouterWorkerState state;

    /*
     * The queue(s) that this worker can receive work from.
     */
    @JsonProperty(value = "queueAssignments")
    private Map<String, RouterQueueAssignment> queueAssignments;

    /*
     * The total capacity score this worker has to manage multiple concurrent
     * jobs.
     */
    @JsonProperty(value = "totalCapacity")
    private Integer totalCapacity;

    /*
     * A set of key/value pairs that are identifying attributes used by the
     * rules engines to make decisions.
     */
    @JsonProperty(value = "labels")
    private Map<String, LabelValue> labels;

    /*
     * A set of non-identifying attributes attached to this worker.
     */
    @JsonProperty(value = "tags")
    private Map<String, LabelValue> tags;

    /*
     * The channel(s) this worker can handle and their impact on the workers
     * capacity.
     */
    @JsonProperty(value = "channelConfigurations")
    private Map<String, ChannelConfiguration> channelConfigurations;

    /*
     * A list of active offers issued to this worker.
     */
    @JsonProperty(value = "offers", access = JsonProperty.Access.WRITE_ONLY)
    private List<RouterJobOffer> offers;

    /*
     * A list of assigned jobs attached to this worker.
     */
    @JsonProperty(value = "assignedJobs", access = JsonProperty.Access.WRITE_ONLY)
    private List<RouterWorkerAssignment> assignedJobs;

    /*
     * A value indicating the workers capacity. A value of '1' means all
     * capacity is consumed. A value of '0' means no capacity is currently
     * consumed.
     */
    @JsonProperty(value = "loadRatio", access = JsonProperty.Access.WRITE_ONLY)
    private Double loadRatio;

    /*
     * A flag indicating this worker is open to receive offers or not.
     */
    @JsonProperty(value = "availableForOffers")
    private Boolean availableForOffers;

    /**
     * Get the id property: The id property.
     *
     * @return the id value.
     */
    public String getId() {
        return this.id;
    }

    /**
     * Get the state property: The current state of the worker.
     *
     * @return the state value.
     */
    public RouterWorkerState getState() {
        return this.state;
    }

    /**
     * Get the queueAssignments property: The queue(s) that this worker can receive work from.
     *
     * @return the queueAssignments value.
     */
    public Map<String, RouterQueueAssignment> getQueueAssignments() {
        return this.queueAssignments;
    }

    /**
     * Set the queueAssignments property: The queue(s) that this worker can receive work from.
     *
     * @param queueAssignments the queueAssignments value to set.
     * @return the RouterWorker object itself.
     */
    public RouterWorker setQueueAssignments(Map<String, RouterQueueAssignment> queueAssignments) {
        this.queueAssignments = queueAssignments;
        return this;
    }

    /**
     * Get the totalCapacity property: The total capacity score this worker has to manage multiple concurrent jobs.
     *
     * @return the totalCapacity value.
     */
    public Integer getTotalCapacity() {
        return this.totalCapacity;
    }

    /**
     * Set the totalCapacity property: The total capacity score this worker has to manage multiple concurrent jobs.
     *
     * @param totalCapacity the totalCapacity value to set.
     * @return the RouterWorker object itself.
     */
    public RouterWorker setTotalCapacity(Integer totalCapacity) {
        this.totalCapacity = totalCapacity;
        return this;
    }

    /**
     * Get the labels property: A set of key/value pairs that are identifying attributes used by the rules engines to
     * make decisions.
     *
     * @return the labels value.
     */
    public Map<String, LabelValue> getLabels() {
        return this.labels;
    }

    /**
     * Set the labels property: A set of key/value pairs that are identifying attributes used by the rules engines to
     * make decisions.
     *
     * @param labels the labels value to set.
     * @return the RouterWorker object itself.
     */
    public RouterWorker setLabels(Map<String, LabelValue> labels) {
        this.labels = labels;
        return this;
    }

    /**
     * Get the tags property: A set of non-identifying attributes attached to this worker.
     *
     * @return the tags value.
     */
    public Map<String, LabelValue> getTags() {
        return this.tags;
    }

    /**
     * Set the tags property: A set of non-identifying attributes attached to this worker.
     *
     * @param tags the tags value to set.
     * @return the RouterWorker object itself.
     */
    public RouterWorker setTags(Map<String, LabelValue> tags) {
        this.tags = tags;
        return this;
    }

    /**
     * Get the channelConfigurations property: The channel(s) this worker can handle and their impact on the workers
     * capacity.
     *
     * @return the channelConfigurations value.
     */
    public Map<String, ChannelConfiguration> getChannelConfigurations() {
        return this.channelConfigurations;
    }

    /**
     * Set the channelConfigurations property: The channel(s) this worker can handle and their impact on the workers
     * capacity.
     *
     * @param channelConfigurations the channelConfigurations value to set.
     * @return the RouterWorker object itself.
     */
    public RouterWorker setChannelConfigurations(Map<String, ChannelConfiguration> channelConfigurations) {
        this.channelConfigurations = channelConfigurations;
        return this;
    }

    /**
     * Get the offers property: A list of active offers issued to this worker.
     *
     * @return the offers value.
     */
    public List<RouterJobOffer> getOffers() {
        return this.offers;
    }

    /**
     * Get the assignedJobs property: A list of assigned jobs attached to this worker.
     *
     * @return the assignedJobs value.
     */
    public List<RouterWorkerAssignment> getAssignedJobs() {
        return this.assignedJobs;
    }

    /**
     * Get the loadRatio property: A value indicating the workers capacity. A value of '1' means all capacity is
     * consumed. A value of '0' means no capacity is currently consumed.
     *
     * @return the loadRatio value.
     */
    public Double getLoadRatio() {
        return this.loadRatio;
    }

    /**
     * Get the availableForOffers property: A flag indicating this worker is open to receive offers or not.
     *
     * @return the availableForOffers value.
     */
    public Boolean isAvailableForOffers() {
        return this.availableForOffers;
    }

    /**
     * Set the availableForOffers property: A flag indicating this worker is open to receive offers or not.
     *
     * @param availableForOffers the availableForOffers value to set.
     * @return the RouterWorker object itself.
     */
    public RouterWorker setAvailableForOffers(Boolean availableForOffers) {
        this.availableForOffers = availableForOffers;
        return this;
    }
}
