package com.za.offline

import androidx.room.Entity
import androidx.room.PrimaryKey
import androidx.room.TypeConverter
import androidx.room.TypeConverters
import com.alibaba.fastjson.JSON

@TypeConverters(InspectionConverter::class)
@Entity(tableName = "offline_update_task_bean")
data class OfflineUpdateTaskBean(
    @PrimaryKey(autoGenerate = true)
    val primaryId: Int? = null,

    //以下为上传状态的参数
    val type: String? = null,
    val taskId: Int? = null,
    val userId: Int? = null,
    val vehicleId: Int? = null,
    val currentState: String? = null,
    val operateTime: String? = null,
    val updateTaskLat: Double? = null,
    val updateTaskLng: Double? = null,
    val updateTaskAddress: String? = null,
    val offlineMode: Int? = null,  //0 正常  1 离线
    val flowType: Int? = null,
    val success: Int? = null, //作业是否完成  0 成功 1不成功  拖车默认成功
    val templatePhotoInfoList: List<String?>? = null, //照片路径，使用@分隔符分开

    //以下为上传图片的参数
    val realTakePhotoTime: String? = null,//真实拍照时间
    val photoSource: Int? = null,//1相机  2 相册  3真实位置
    val time: String? = null,// 拍照时间
    val imageLat: Float? = null,
    val imageLng: Float? = null,
    val imageAddress: String? = null,

    val imageIndex: Int? = null,
    val imageLocalPath: String? = null,
    val imageUploadPath: String? = null,
    val advanceTime: Long? = null,
    val sort: Int?=null,
    val needWater:Boolean?=null,
    val needPhoneBrand:Boolean?=null,
    val photoLocalWaterMarkerPath: String? = null,


    //以下为电子工单状态
    val eleState: Int? = null,
    val hasDamage: Int? = null, //是否有算上 1 有
    val hasSuccess: Int? = null, // 作业是否完成  1成功 0失败
    val customerSignPath: String? = null, //客户签名照片
    val recipientSignPath: String? = null, //接车人签名
    val waitstaffSignPath: String? = null, //服务人员签名
    val damageFileList: List<String?>? = null, //损伤文件列表   //照片路径，使用,分隔符分开
    val userOrderCode: String? = null, //仅在历史补传电子工单时传
    val tyreNumber: Int? = null, //小轮个数
    val eleLng: Double? = null,
    val eleLat: Double? = null,
    val isFinish: Boolean = false, //订单是否完成进入历史  true  完成


    //以下为自定义字段
    val userOrderId: Int? = null,
    val taskCode: String? = null,
    val isUpload: Int = 0,//是否已经上传  0  未上传   1  已经上传
    val offlineTime: Long = System.currentTimeMillis(),  //添加离线的时间
    val offlineTitle: String? = null,
    val offlineTimeStr: String? = com.blankj.utilcode.util.TimeUtils.getNowString(),
    val offlineType: Int? = null,// 1 订单状态  2 订单图片  3 电子工单状态  4 电子工单损伤照片  5客户签名照片 6接车人签名照片 7服务人员签名照片  8 任务完成
)

class InspectionConverter {
    @TypeConverter
    fun stringToObject(value: String?): List<String?>? {
        if (value.isNullOrBlank()) {
            return null
        }
        val str = JSON.parseArray(value, String::class.java)
        return str
    }

    @TypeConverter
    fun objectToString(list: List<String?>?): String? {
        if (list.isNullOrEmpty()) {
            return null
        }
        val str = JSON.toJSONString(list)
        return str
    }
}