/*
 * appNG REST API
 * The REST API for appNG
 *
 * The version of the OpenAPI document: 1.0.0
 * Contact: matthias.mueller@appng.org
 *
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */


package org.appng.openapi.model;

import java.util.Objects;
import java.util.Arrays;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonTypeName;
import com.fasterxml.jackson.annotation.JsonValue;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.appng.openapi.model.FieldType;
import org.appng.openapi.model.Sort;
import org.appng.openapi.model.ValidationRule;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;

/**
 * A field that is part of a datasource.
 */
@ApiModel(description = "A field that is part of a datasource.")
@JsonPropertyOrder({
  Field.JSON_PROPERTY_NAME,
  Field.JSON_PROPERTY_LABEL,
  Field.JSON_PROPERTY_FIELD_TYPE,
  Field.JSON_PROPERTY_SORT,
  Field.JSON_PROPERTY_FORMAT,
  Field.JSON_PROPERTY_RULES,
  Field.JSON_PROPERTY_FIELDS
})
@JsonTypeName("Field")
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2023-03-20T12:57:48.851+01:00[Europe/Berlin]")
public class Field {
  public static final String JSON_PROPERTY_NAME = "name";
  private String name;

  public static final String JSON_PROPERTY_LABEL = "label";
  private String label;

  public static final String JSON_PROPERTY_FIELD_TYPE = "fieldType";
  private FieldType fieldType;

  public static final String JSON_PROPERTY_SORT = "sort";
  private Sort sort;

  public static final String JSON_PROPERTY_FORMAT = "format";
  private String format;

  public static final String JSON_PROPERTY_RULES = "rules";
  private List<ValidationRule> rules = null;

  public static final String JSON_PROPERTY_FIELDS = "fields";
  private Map<String, Field> fields = null;


  public Field name(String name) {
    
    this.name = name;
    return this;
  }

   /**
   * The name for this field.
   * @return name
  **/
  @ApiModelProperty(required = true, value = "The name for this field.")
  @JsonProperty(JSON_PROPERTY_NAME)
  @JsonInclude(value = JsonInclude.Include.ALWAYS)

  public String getName() {
    return name;
  }


  @JsonProperty(JSON_PROPERTY_NAME)
  @JsonInclude(value = JsonInclude.Include.ALWAYS)
  public void setName(String name) {
    this.name = name;
  }


  public Field label(String label) {
    
    this.label = label;
    return this;
  }

   /**
   * The label for this field.
   * @return label
  **/
  @javax.annotation.Nullable
  @ApiModelProperty(value = "The label for this field.")
  @JsonProperty(JSON_PROPERTY_LABEL)
  @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)

  public String getLabel() {
    return label;
  }


  @JsonProperty(JSON_PROPERTY_LABEL)
  @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
  public void setLabel(String label) {
    this.label = label;
  }


  public Field fieldType(FieldType fieldType) {
    
    this.fieldType = fieldType;
    return this;
  }

   /**
   * Get fieldType
   * @return fieldType
  **/
  @ApiModelProperty(required = true, value = "")
  @JsonProperty(JSON_PROPERTY_FIELD_TYPE)
  @JsonInclude(value = JsonInclude.Include.ALWAYS)

  public FieldType getFieldType() {
    return fieldType;
  }


  @JsonProperty(JSON_PROPERTY_FIELD_TYPE)
  @JsonInclude(value = JsonInclude.Include.ALWAYS)
  public void setFieldType(FieldType fieldType) {
    this.fieldType = fieldType;
  }


  public Field sort(Sort sort) {
    
    this.sort = sort;
    return this;
  }

   /**
   * Get sort
   * @return sort
  **/
  @javax.annotation.Nullable
  @ApiModelProperty(value = "")
  @JsonProperty(JSON_PROPERTY_SORT)
  @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)

  public Sort getSort() {
    return sort;
  }


  @JsonProperty(JSON_PROPERTY_SORT)
  @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
  public void setSort(Sort sort) {
    this.sort = sort;
  }


  public Field format(String format) {
    
    this.format = format;
    return this;
  }

   /**
   * The format for this field, depending on its type.
   * @return format
  **/
  @javax.annotation.Nullable
  @ApiModelProperty(value = "The format for this field, depending on its type.")
  @JsonProperty(JSON_PROPERTY_FORMAT)
  @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)

  public String getFormat() {
    return format;
  }


  @JsonProperty(JSON_PROPERTY_FORMAT)
  @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
  public void setFormat(String format) {
    this.format = format;
  }


  public Field rules(List<ValidationRule> rules) {
    
    this.rules = rules;
    return this;
  }

  public Field addRulesItem(ValidationRule rulesItem) {
    if (this.rules == null) {
      this.rules = new ArrayList<>();
    }
    this.rules.add(rulesItem);
    return this;
  }

   /**
   * The validation rules that should be applied for this field.
   * @return rules
  **/
  @javax.annotation.Nullable
  @ApiModelProperty(value = "The validation rules that should be applied for this field.")
  @JsonProperty(JSON_PROPERTY_RULES)
  @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)

  public List<ValidationRule> getRules() {
    return rules;
  }


  @JsonProperty(JSON_PROPERTY_RULES)
  @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
  public void setRules(List<ValidationRule> rules) {
    this.rules = rules;
  }


  public Field fields(Map<String, Field> fields) {
    
    this.fields = fields;
    return this;
  }

  public Field putFieldsItem(String key, Field fieldsItem) {
    if (this.fields == null) {
      this.fields = new HashMap<>();
    }
    this.fields.put(key, fieldsItem);
    return this;
  }

   /**
   * The child fields of this field.
   * @return fields
  **/
  @javax.annotation.Nullable
  @ApiModelProperty(value = "The child fields of this field.")
  @JsonProperty(JSON_PROPERTY_FIELDS)
  @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)

  public Map<String, Field> getFields() {
    return fields;
  }


  @JsonProperty(JSON_PROPERTY_FIELDS)
  @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
  public void setFields(Map<String, Field> fields) {
    this.fields = fields;
  }


  @Override
  public boolean equals(Object o) {
    if (this == o) {
      return true;
    }
    if (o == null || getClass() != o.getClass()) {
      return false;
    }
    Field field = (Field) o;
    return Objects.equals(this.name, field.name) &&
        Objects.equals(this.label, field.label) &&
        Objects.equals(this.fieldType, field.fieldType) &&
        Objects.equals(this.sort, field.sort) &&
        Objects.equals(this.format, field.format) &&
        Objects.equals(this.rules, field.rules) &&
        Objects.equals(this.fields, field.fields);
  }

  @Override
  public int hashCode() {
    return Objects.hash(name, label, fieldType, sort, format, rules, fields);
  }

  @Override
  public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("class Field {\n");
    sb.append("    name: ").append(toIndentedString(name)).append("\n");
    sb.append("    label: ").append(toIndentedString(label)).append("\n");
    sb.append("    fieldType: ").append(toIndentedString(fieldType)).append("\n");
    sb.append("    sort: ").append(toIndentedString(sort)).append("\n");
    sb.append("    format: ").append(toIndentedString(format)).append("\n");
    sb.append("    rules: ").append(toIndentedString(rules)).append("\n");
    sb.append("    fields: ").append(toIndentedString(fields)).append("\n");
    sb.append("}");
    return sb.toString();
  }

  /**
   * Convert the given object to string with each line indented by 4 spaces
   * (except the first line).
   */
  private String toIndentedString(Object o) {
    if (o == null) {
      return "null";
    }
    return o.toString().replace("\n", "\n    ");
  }

}

