package com.ttstd.dialer.db.contact;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.room.Entity;
import androidx.room.PrimaryKey;

import com.google.gson.Gson;
import com.google.gson.JsonParser;

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

@Entity(tableName = "contacts")
public class ContactInfo implements Serializable {

    @PrimaryKey(autoGenerate = true)
    private int id;
    private String name;
    private String phoneNumber;
    private String avatar;
    private String wxid;
    private int position;

    public ContactInfo(String name, String phoneNumber, int position) {
        this.name = name;
        this.phoneNumber = phoneNumber;
        this.position = position;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPhoneNumber() {
        return phoneNumber;
    }

    public void setPhoneNumber(String phoneNumber) {
        this.phoneNumber = phoneNumber;
    }

    public String getAvatar() {
        return avatar;
    }

    public void setAvatar(String avatar) {
        this.avatar = avatar;
    }

    public String getWxid() {
        return wxid;
    }

    public void setWxid(String wxid) {
        this.wxid = wxid;
    }

    public int getPosition() {
        return position;
    }

    public void setPosition(int position) {
        this.position = position;
    }

    @Override
    public boolean equals(@Nullable Object obj) {
        if (obj instanceof ContactInfo) {
            return Objects.equals(((ContactInfo) obj).phoneNumber, phoneNumber)
                    || ((ContactInfo) obj).id == id;
        }
        return false;
    }

    @NonNull
    @Override
    public String toString() {
        return JsonParser.parseString(new Gson().toJson(this)).getAsJsonObject().toString();
    }
}

