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 账号名称
    var imagePublishUrl:String?= null // define: 2023/8/25 图片发布地址
    var imageThumbnailPublishUrl:String?=null // define: 2023/8/25 图片缩略图发布地址
    var videoPublishUrl:String?= null // define: 2023/8/25 视频发布地址
    var netCaseServiceUrl:String?=null // define: 2023/8/25 在线案件服务地址

    /**
     * 构造方法
     * @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")
            model.imagePublishUrl = obj.getString("imagePublishUrl")
            model.imageThumbnailPublishUrl = obj.getString("imageThumbnailPublishUrl")
            model.videoPublishUrl = obj.getString("videoPublishUrl")
            model.netCaseServiceUrl = obj.getString("netCaseServiceUrl")
            return model
        }
    }

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