package com.carmaintenance.data.model

import com.google.gson.annotations.SerializedName

/**
 * 用户实体
 */
data class User(
    @SerializedName("userId")
    val userId: Int,
    @SerializedName("username")
    val username: String,
    @SerializedName("realName")
    val realName: String,
    @SerializedName("phone")
    val phone: String,
    @SerializedName("email")
    val email: String? = null,
    @SerializedName("role")
    val role: String,
    @SerializedName("status")
    val status: Int
) {
    enum class Role(val value: String) {
        ADMIN("admin"),
        STAFF("staff"),
        CUSTOMER("customer");

        companion object {
            fun fromValue(value: String): Role {
                return values().find { it.value == value } ?: CUSTOMER
            }
        }
    }

    val roleEnum: Role
        get() = Role.fromValue(role)

    val isActive: Boolean
        get() = status == 1
}
