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

package com.azure.resourcemanager.apimanagement.models;

import com.azure.core.annotation.Fluent;
import com.azure.core.util.logging.ClientLogger;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.List;
import java.util.Map;

/** Operation parameters details. */
@Fluent
public final class ParameterContract {
    /*
     * Parameter name.
     */
    @JsonProperty(value = "name", required = true)
    private String name;

    /*
     * Parameter description.
     */
    @JsonProperty(value = "description")
    private String description;

    /*
     * Parameter type.
     */
    @JsonProperty(value = "type", required = true)
    private String type;

    /*
     * Default parameter value.
     */
    @JsonProperty(value = "defaultValue")
    private String defaultValue;

    /*
     * Specifies whether parameter is required or not.
     */
    @JsonProperty(value = "required")
    private Boolean required;

    /*
     * Parameter values.
     */
    @JsonProperty(value = "values")
    private List<String> values;

    /*
     * Schema identifier.
     */
    @JsonProperty(value = "schemaId")
    private String schemaId;

    /*
     * Type name defined by the schema.
     */
    @JsonProperty(value = "typeName")
    private String typeName;

    /*
     * Exampled defined for the parameter.
     */
    @JsonProperty(value = "examples")
    @JsonInclude(value = JsonInclude.Include.NON_NULL, content = JsonInclude.Include.ALWAYS)
    private Map<String, ParameterExampleContract> examples;

    /**
     * Get the name property: Parameter name.
     *
     * @return the name value.
     */
    public String name() {
        return this.name;
    }

    /**
     * Set the name property: Parameter name.
     *
     * @param name the name value to set.
     * @return the ParameterContract object itself.
     */
    public ParameterContract withName(String name) {
        this.name = name;
        return this;
    }

    /**
     * Get the description property: Parameter description.
     *
     * @return the description value.
     */
    public String description() {
        return this.description;
    }

    /**
     * Set the description property: Parameter description.
     *
     * @param description the description value to set.
     * @return the ParameterContract object itself.
     */
    public ParameterContract withDescription(String description) {
        this.description = description;
        return this;
    }

    /**
     * Get the type property: Parameter type.
     *
     * @return the type value.
     */
    public String type() {
        return this.type;
    }

    /**
     * Set the type property: Parameter type.
     *
     * @param type the type value to set.
     * @return the ParameterContract object itself.
     */
    public ParameterContract withType(String type) {
        this.type = type;
        return this;
    }

    /**
     * Get the defaultValue property: Default parameter value.
     *
     * @return the defaultValue value.
     */
    public String defaultValue() {
        return this.defaultValue;
    }

    /**
     * Set the defaultValue property: Default parameter value.
     *
     * @param defaultValue the defaultValue value to set.
     * @return the ParameterContract object itself.
     */
    public ParameterContract withDefaultValue(String defaultValue) {
        this.defaultValue = defaultValue;
        return this;
    }

    /**
     * Get the required property: Specifies whether parameter is required or not.
     *
     * @return the required value.
     */
    public Boolean required() {
        return this.required;
    }

    /**
     * Set the required property: Specifies whether parameter is required or not.
     *
     * @param required the required value to set.
     * @return the ParameterContract object itself.
     */
    public ParameterContract withRequired(Boolean required) {
        this.required = required;
        return this;
    }

    /**
     * Get the values property: Parameter values.
     *
     * @return the values value.
     */
    public List<String> values() {
        return this.values;
    }

    /**
     * Set the values property: Parameter values.
     *
     * @param values the values value to set.
     * @return the ParameterContract object itself.
     */
    public ParameterContract withValues(List<String> values) {
        this.values = values;
        return this;
    }

    /**
     * Get the schemaId property: Schema identifier.
     *
     * @return the schemaId value.
     */
    public String schemaId() {
        return this.schemaId;
    }

    /**
     * Set the schemaId property: Schema identifier.
     *
     * @param schemaId the schemaId value to set.
     * @return the ParameterContract object itself.
     */
    public ParameterContract withSchemaId(String schemaId) {
        this.schemaId = schemaId;
        return this;
    }

    /**
     * Get the typeName property: Type name defined by the schema.
     *
     * @return the typeName value.
     */
    public String typeName() {
        return this.typeName;
    }

    /**
     * Set the typeName property: Type name defined by the schema.
     *
     * @param typeName the typeName value to set.
     * @return the ParameterContract object itself.
     */
    public ParameterContract withTypeName(String typeName) {
        this.typeName = typeName;
        return this;
    }

    /**
     * Get the examples property: Exampled defined for the parameter.
     *
     * @return the examples value.
     */
    public Map<String, ParameterExampleContract> examples() {
        return this.examples;
    }

    /**
     * Set the examples property: Exampled defined for the parameter.
     *
     * @param examples the examples value to set.
     * @return the ParameterContract object itself.
     */
    public ParameterContract withExamples(Map<String, ParameterExampleContract> examples) {
        this.examples = examples;
        return this;
    }

    /**
     * Validates the instance.
     *
     * @throws IllegalArgumentException thrown if the instance is not valid.
     */
    public void validate() {
        if (name() == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException("Missing required property name in model ParameterContract"));
        }
        if (type() == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException("Missing required property type in model ParameterContract"));
        }
        if (examples() != null) {
            examples()
                .values()
                .forEach(
                    e -> {
                        if (e != null) {
                            e.validate();
                        }
                    });
        }
    }

    private static final ClientLogger LOGGER = new ClientLogger(ParameterContract.class);
}
