package io.delphiplatform.api.v3.model.datahealth;

import com.fasterxml.jackson.annotation.JsonProperty;

import org.openapitools.jackson.nullable.JsonNullable;
import org.springframework.format.annotation.DateTimeFormat;

import java.time.LocalDate;
import java.util.Objects;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;

/**
 * Object containing the data completeness for a single DSP
 */
public class DataCompleteness {

    @JsonProperty("dsp")
    private String dsp;

    @JsonProperty("updated_date")
    @DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
    private JsonNullable<LocalDate> updatedDate = JsonNullable.undefined();

    public DataCompleteness() {
    }

    public DataCompleteness(String dsp, LocalDate updatedDate) {
        this.dsp = dsp;
        this.updatedDate(updatedDate);
    }

    public DataCompleteness dsp(String dspId) {
        this.dsp = dspId;
        return this;
    }

    /**
     * Primary key identifier for Dsp
     *
     * @return dspId
     */
    @NotNull
    public String getDsp() {
        return dsp;
    }

    public void setDsp(String dsp) {
        this.dsp = dsp;
    }

    public DataCompleteness updatedDate(LocalDate updatedDate) {
        this.updatedDate = JsonNullable.of(updatedDate);
        return this;
    }

    /**
     * ISO 8601 date in format `YYYY-MM-DD`
     *
     * @return updatedDate
     */
    @NotNull
    @Valid
    @Pattern(regexp = "^\\d{4}-\\d{2}-\\d{2}$")
    public JsonNullable<LocalDate> getUpdatedDate() {
        return updatedDate;
    }

    public void setUpdatedDate(JsonNullable<LocalDate> updatedDate) {
        this.updatedDate = updatedDate;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        DataCompleteness dataCompleteness = (DataCompleteness) o;
        return Objects.equals(this.dsp, dataCompleteness.dsp) &&
            Objects.equals(this.updatedDate, dataCompleteness.updatedDate);
    }

    @Override
    public int hashCode() {
        return Objects.hash(dsp, updatedDate);
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("class DataCompleteness {\n");

        sb.append("    dspId: ").append(toIndentedString(dsp)).append("\n");
        sb.append("    updatedDate: ").append(toIndentedString(updatedDate)).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    ");
    }
}
