// 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.DistributionPolicyConstructorProxy;
import com.azure.communication.jobrouter.implementation.converters.DistributionPolicyAdapter;
import com.azure.communication.jobrouter.implementation.models.DistributionPolicyInternal;
import com.azure.core.annotation.Fluent;
import com.fasterxml.jackson.annotation.JsonProperty;

import java.time.Duration;

/** Policy governing how jobs are distributed to workers. */
@Fluent
public final class DistributionPolicy {
    /**
     * Public constructor.
     *
     * @param id The id
     */
    public DistributionPolicy(String id) {
        this.id = id;
    }

    /**
     * Package-private constructor of the class, used internally.
     *
     * @param internal The internal DistributionPolicy
     */
    DistributionPolicy(DistributionPolicyInternal internal) {
        id = internal.getId();

        setName(internal.getName());
        setMode(DistributionPolicyAdapter.convertDistributionModeToPublic(internal.getMode()));
        setOfferExpiresAfter(Duration.ofSeconds(internal.getOfferExpiresAfterSeconds().longValue()));
    }

    static {
        DistributionPolicyConstructorProxy.setAccessor(internal -> new DistributionPolicy(internal));
    }

    /*
     * The unique identifier of the policy.
     */
    @JsonProperty(value = "id", access = JsonProperty.Access.WRITE_ONLY)
    private String id;

    /*
     * The human readable name of the policy.
     */
    @JsonProperty(value = "name")
    private String name;

    /*
     * The number of seconds after which any offers created under this policy
     * will be expired.
     */
    @JsonProperty(value = "offerExpiresAfterSeconds")
    private Duration offerExpiresAfter;

    /*
     * Abstract base class for defining a distribution mode
     */
    @JsonProperty(value = "mode")
    private DistributionMode mode;

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

    /**
     * Get the name property: The human readable name of the policy.
     *
     * @return the name value.
     */
    public String getName() {
        return this.name;
    }

    /**
     * Set the name property: The human readable name of the policy.
     *
     * @param name the name value to set.
     * @return the DistributionPolicy object itself.
     */
    public DistributionPolicy setName(String name) {
        this.name = name;
        return this;
    }

    /**
     * Get the offerExpiresAfterSeconds property: The number of seconds after which any offers created under this policy
     * will be expired.
     *
     * @return the offerExpiresAfterSeconds value.
     */
    public Duration getOfferExpiresAfter() {
        return this.offerExpiresAfter;
    }

    /**
     * Set the offerExpiresAfterSeconds property: The number of seconds after which any offers created under this policy
     * will be expired.
     *
     * @param offerExpiresAfter the offerExpiresAfterSeconds value to set.
     * @return the DistributionPolicy object itself.
     */
    public DistributionPolicy setOfferExpiresAfter(Duration offerExpiresAfter) {
        this.offerExpiresAfter = offerExpiresAfter;
        return this;
    }

    /**
     * Get the mode property: Abstract base class for defining a distribution mode.
     *
     * @return the mode value.
     */
    public DistributionMode getMode() {
        return this.mode;
    }

    /**
     * Set the mode property: Abstract base class for defining a distribution mode.
     *
     * @param mode the mode value to set.
     * @return the DistributionPolicy object itself.
     */
    public DistributionPolicy setMode(DistributionMode mode) {
        this.mode = mode;
        return this;
    }
}
