package com.app.simplitend.welcome.welcomepatient.fragments.contacts.mvvm;

import androidx.annotation.Nullable;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Objects;

public class Contact implements Serializable {

    public String first_name, imageUri, phone_number, relationship, email_address
            , extra_phone_numbers;

    public String is_sos, updated_at, created_at;

    @Nullable
    public String country_code;

    public long id;

    public Contact(ArrayList<Contact> contacts){
        if (contacts != null && !contacts.isEmpty()){
            this.first_name = contacts.get(0).first_name;
            this.email_address = contacts.get(0).email_address;
            this.imageUri = contacts.get(0).imageUri;

            StringBuilder stringBuilder = new StringBuilder();

            for (int i = 0; i < contacts.size(); i++) {
                if (contacts.get(i) != null){
                    stringBuilder.append(contacts.get(i).phone_number);

                    // adding comma only if it is not the last item
                    if (i < contacts.size()-1){
                        stringBuilder.append(",");
                    }
                }
            }

            this.extra_phone_numbers = stringBuilder.toString();
        }
    }

    public Contact(String name){
        this.first_name = first_name;
    }

    public Contact(String first_name, String phoneNumber){
        this.first_name= first_name;
        this.phone_number = phoneNumber;
    }

    public Contact(String first_name, String phone_number, String relationship, String email_address, String is_sos, String updated_at, String created_at) {
        this.first_name = first_name;
        this.phone_number = phone_number;
        this.relationship = relationship;
        this.email_address = email_address;
        this.is_sos = is_sos;
        this.updated_at = updated_at;
        this.created_at = created_at;
    }

    @Override
    public String toString() {
        return "Contact{" +
                "first_name='" + first_name + '\'' +
                ", imageUri='" + imageUri + '\'' +
                ", phone_number='" + phone_number + '\'' +
                ", relationship='" + relationship + '\'' +
                ", email_address='" + email_address + '\'' +
                '}';
    }

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

    @Override
    public int hashCode() {
        return Objects.hash(phone_number);
    }
}
