package com.application.tak.takapplication.data_model;

import android.widget.Toast;

import java.util.regex.Pattern;

/**
 * Created by azielinska on 11/05/2017.
 */
public class Adress
{
    private int _Id;
    private String _City = "";
    private String _Road = "";
    private String _PostCode = "";
    private String _RoadNo = "";

    public int get_Id() {
        return _Id;
    }

    public void set_Id(int _Id) {
        this._Id = _Id;
    }

    public String get_City() {
        return _City;
    }

    public void set_City(String _City) {

        if(CheckIsDataCorrect(_City))
            this._City = _City;
        else
            this._City = "";
    }

    public String get_Road() {
        return _Road;
    }

    public void set_Road(String _Road) {
        if(CheckIsDataCorrect(_Road))
            this._Road = _Road;
        else
            this._Road = "";
    }

    public String get_PostCode() {
        return _PostCode;
    }

    public void set_PostCode(String _PostCode) {

        if(CheckPostCodeCorrect(_PostCode))
            this._PostCode = PreparePostCode(_PostCode);
        else
            this._PostCode = "";
    }

    public String get_RoadNo() {
        return _RoadNo;
    }

    public void set_RoadNo(String _RoadNo)
    {
     if(_RoadNo != null)
        this._RoadNo = _RoadNo;
     else
         this._RoadNo = "";
    }

    boolean CheckPostCodeCorrect(String text)
    {
        if(Pattern.matches("^\\d{2}\\-?\\d{3}$", text))
        {
            return true;
        }
        return false;
    }

    boolean CheckIsDataCorrect(String str)
    {
        if(str!= null && str.trim().length() >= 3)
            return true;
        return false;
    }

    String PreparePostCode(String postcode)
    {
        if(postcode.contains("-"))
            return postcode;
        else
            return postcode = postcode.substring(0,2)+"-"+postcode.substring(2,5);

    }
}
