/**
 * @type {AddressModel}
 */


export default class AddressModel{
    constructor(address = {}) {
        this.postal_code = (address.postal_code)? address.postal_code:  "";
        this.street = (address.street)? address.street : "" ;
        this.number = (address.number)? address.number : "";
        this.complement = (address.complement)? address.complement : "";
        this.neighborhood = (address.neighborhood)? address.neighborhood : "";
        this.code_ibge = (address.city)? address.city.ibge_code :"";
        this.reference = (address.reference)? address.reference : "";
        this.deliverable = (typeof( address.deliverable ) === 'undefined' )? true : address.deliverable;
        this.proof = (address.proof_url)? address.proof_url : "";
        this.uf= (address.city)? address.city.state.uf : "";
        this.type = (address.type)? address.type : "RESIDENTIAL"
        this.proof_url = (address.proof_url)? address.proof_url : "";
    }

postalCodeIsValid(){

    if(this.postal_code.trim().replace(/[^\d]+/g,'').length === 8){
        return true;
    }
    return false;

}

streetIsValid(){
    if(this.street.trim().length > 3){
        return true;
    }
    return false;
}

neighborhoodIsValid(){
    if(this.neighborhood.trim().length > 3){
        return true;
    }
    return false;
}

complementIsValid(){
    if(this.complement.trim().length > 3){
        return true;
    }
    return false;
}

codeIbgeIsValid(){
    if(this.code_ibge.trim().length === 7){
        return true;
    }
    return false;
}

ufIsValid(){

    if(this.uf.trim().length === 2){
        return true;
    }

}

numberIsValid(){
    if(this.number == ""){
        return false;
    }

    return true;
}

    isValid(){

        return this.postalCodeIsValid() && this.streetIsValid() && this.neighborhoodIsValid() && this.complementIsValid() && 
        this.codeIbgeIsValid() && this.ufIsValid();
    }

}