package com.zyzf.coffeepreorder.database.model

import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.Ignore
import androidx.room.PrimaryKey

@Entity(tableName = "user")
data class User(
    @PrimaryKey(autoGenerate = true)
    val uid: Int = 0,
    @ColumnInfo(name = "login")
    var login: String,
    @ColumnInfo(name = "fio")
    var fio: String,
    @ColumnInfo(name = "phone")
    var phone: String,
    @ColumnInfo(name = "password")
    var password: String,
    @ColumnInfo(name = "role")
    var role: String
) {
    @Ignore
    constructor(
        login: String,
        fio: String,
        phone: String,
        password: String,
        role: String
    ) : this(0, login, fio, phone, password, role)

    companion object {
        fun getUser(index: Int = 0): User {
            return User(
                index,
                "",
                "",
                "",
                "",
                "user"
            )
        }
    }

    override fun equals(other: Any?): Boolean {
        if (this === other) return true
        if (javaClass != other?.javaClass) return false
        other as User
        if (uid != other.uid) return false
        if (login != other.login) return false
        if (fio != other.fio) return false
        if (phone != other.phone) return false
        if (password != other.password) return false
        return role == other.role
    }

    override fun hashCode(): Int {
        var result = uid
        result = 31 * result + login.hashCode()
        result = 31 * result + fio.hashCode()
        result = 31 * result + phone.hashCode()
        result = 31 * result + password.hashCode()
        result = 31 * result + role.hashCode()
        return result
    }
}
