package com.cr.models

import com.cr.common.ClassManager
import org.json.JSONObject

/**
 * 操作系统：MAC系统
 * 创建者：王成
 * 创建日期：2023/4/6 11:29
 * 描述：账户模型
 */
class UserModel constructor():iNetDataModel<UserModel>{
    var userId: String? = ""   // define: 2023/4/6 账号Id
    var userPwd: String? = ""   // define: 2023/4/6 密码
    var userName: String? = ""   // define: 2023/4/6 账号名称

    /**
     * 构造方法
     * @param userId String 账号Id
     * @param userPwd String 密码
     * @constructor
     */
    constructor(userId: String, userPwd: String) : this() {
        this.userId = userId
        this.userPwd = userPwd
    }

    companion object:iJSONModel<UserModel>{
        /**
         * 转换为模型
         * @param json String JSON字符串
         * @return UserModel?
         */
        override fun toModel(json: String): UserModel? {
            var obj = JSONObject(json)
            var model = UserModel()
            model.userId = obj.getString("userId")
            model.userPwd = obj.getString("userPwd")
            model.userName = obj.getString("userName")
            return model
        }
    }

    /**
     * 转换为JSON字符串
     * @return String
     */
    override fun toJSON(): String {
        var jsonObj: JSONObject = ClassManager.fieldsToJSONObject(this)
        return jsonObj.toString()
    }
}