package ru.stqa.pft.addressbook.model;

import ru.stqa.pft.addressbook.appmanager.RandomDataGenerator;

public class ContactData {
    private int id;
    private String firstname;
    private String middlename;
    private String lastname;
    private String title;
    private String address;
    private String homePhone;
    private String mobilePhone;
    private String workPhone;
    private String allPhones;
    private String email;
    private String group;

    public ContactData() {
        this.id = 0;
        this.firstname = "";
        this.middlename = "";
        this.lastname = "";
        this.title = "";
        this.address = "";
        this.homePhone = "";
        this.mobilePhone = "";
        this.workPhone = "";
        this.email = "";
        this.group = null;
    }

    public static ContactData getWithRandomData() {
        RandomDataGenerator rnd = new RandomDataGenerator();
        ContactData contact = new ContactData();
        contact
                .withFirstname(rnd.getFirstnameEng())
                .withMiddlename("E.")
                .withLastname(rnd.getSurnameEng())
                .withTitle("Dr.")
                .withAddress(rnd.getAddressEng())
                .withHomePhone(rnd.getPhone())
                .withMobilePhone(rnd.getPhone())
                .withWorkPhone(rnd.getPhone())
                .withEmail(rnd.getEmail());
        return contact;
    }

    public int getId() { return id; }

    public ContactData withId(int id) {
        this.id = id;
        return this;
    }

    public String getFirstname() {
        return firstname;
    }

    public ContactData withFirstname(String firstname) {
        this.firstname = firstname;
        return this;
    }

    public String getMiddlename() {
        return middlename;
    }

    public ContactData withMiddlename(String middlename) {
        this.middlename = middlename;
        return this;
    }

    public String getLastname() {
        return lastname;
    }

    public ContactData withLastname(String lastname) {
        this.lastname = lastname;
        return this;
    }

    public String getTitle() {
        return title;
    }

    public ContactData withTitle(String title) {
        this.title = title;
        return this;
    }

    public String getAddress() {
        return address;
    }

    public ContactData withAddress(String address) {
        this.address = address;
        return this;
    }

    public String getHomePhone() {
        return homePhone;
    }

    public ContactData withHomePhone(String homePhone) {
        this.homePhone = homePhone;
        return this;
    }

    public String getMobilePhone() {
        return mobilePhone;
    }

    public ContactData withMobilePhone(String mobilePhone) {
        this.mobilePhone = mobilePhone;
        return this;
    }

    public String getWorkPhone() {
        return workPhone;
    }

    public ContactData withWorkPhone(String workPhone) {
        this.workPhone = workPhone;
        return this;
    }

    public String getAllPhones() {
        return allPhones;
    }

    public ContactData withAllPhones(String allPhones) {
        this.allPhones = allPhones;
        return this;
    }

    public String getEmail() {
        return email;
    }

    public ContactData withEmail(String email) {
        this.email = email;
        return this;
    }

    public String getGroup() {
        return group;
    }

    public ContactData withGroup(String group) {
        this.group = group;
        return this;
    }

    @Override
    public String toString() {
        return "ContactData{" +
                "id='" + id + '\'' +
                ", firstname='" + firstname + '\'' +
                ", lastname='" + lastname + '\'' +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        ContactData that = (ContactData) o;

        if (id != that.id) return false;
        if (firstname != null ? !firstname.equals(that.firstname) : that.firstname != null) return false;
        return lastname != null ? lastname.equals(that.lastname) : that.lastname == null;
    }

    @Override
    public int hashCode() {
        int result = id;
        result = 31 * result + (firstname != null ? firstname.hashCode() : 0);
        result = 31 * result + (lastname != null ? lastname.hashCode() : 0);
        return result;
    }
}

@@ -1230,24 +1230,46 @@
 thHomePhone(
+Math.random() %3E 0.3 ? 
 rnd.getPhone
@@ -1262,32 +1262,37 @@
 ? rnd.getPhone()
+ : %22%22
 )%0A              
@@ -1306,24 +1306,46 @@
 MobilePhone(
+Math.random() %3E 0.3 ? 
 rnd.getPhone
@@ -1338,32 +1338,37 @@
 ? rnd.getPhone()
+ : %22%22
 )%0A              
@@ -1384,16 +1384,38 @@
 rkPhone(
+Math.random() %3E 0.3 ? 
 rnd.getP
@@ -1420,16 +1420,21 @@
 tPhone()
+ : %22%22
 )%0A      

add chance of empty phone to contact random data generation