package io.delphiplatform.api.v3.model;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;

import java.util.Objects;

import javax.validation.constraints.NotNull;

import io.delphiplatform.api.v3.rdb.entity.RegionEntity;

/**
 * Region
 */
@JsonPropertyOrder(alphabetic = true)
public class Region {

    @JsonProperty("region_id")
    private String regionId;

    @JsonProperty("country_code")
    private String countryCode;

    @JsonProperty("country_name")
    private String countryName;

    public static Region from(RegionEntity region) {
        if (region == null) {
            return null;
        }
        return new Region()
            .regionId(region.getRegionId())
            .countryCode(region.getCountryCode())
            .countryName(region.getCountryName());
    }

    public Region regionId(String regionId) {
        this.regionId = regionId;
        return this;
    }

    /**
     * Primary key identifier for Region. Same as the country_code
     *
     * @return regionId
     */
    @NotNull
    public String getRegionId() {
        return regionId;
    }

    public void setRegionId(String regionId) {
        this.regionId = regionId;
    }

    public Region countryCode(String countryCode) {
        this.countryCode = countryCode;
        return this;
    }

    /**
     * Unique ISO 3166 alpha 2 code.
     *
     * @return countryCode
     */
    @NotNull
    public String getCountryCode() {
        return countryCode;
    }

    public void setCountryCode(String countryCode) {
        this.countryCode = countryCode;
    }

    public Region countryName(String countryName) {
        this.countryName = countryName;
        return this;
    }

    /**
     * ISO 3166 country name.
     *
     * @return countryName
     */
    @NotNull
    public String getCountryName() {
        return countryName;
    }

    public void setCountryName(String countryName) {
        this.countryName = countryName;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        Region region = (Region) o;
        return Objects.equals(this.regionId, region.regionId) &&
            Objects.equals(this.countryCode, region.countryCode) &&
            Objects.equals(this.countryName, region.countryName);
    }

    @Override
    public int hashCode() {
        return Objects.hash(regionId, countryCode, countryName);
    }

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

        sb.append("    regionId: ").append(toIndentedString(regionId)).append("\n");
        sb.append("    countryCode: ").append(toIndentedString(countryCode)).append("\n");
        sb.append("    countryName: ").append(toIndentedString(countryName)).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    ");
    }
}
