package com.carmaintenance.data.model

import com.google.gson.annotations.SerializedName

/**
 * 维保工单实体
 */
data class ServiceOrder(
    @SerializedName("orderId")
    val orderId: Int,
    @SerializedName("orderNo")
    val orderNo: String,
    @SerializedName("vehicleId")
    val vehicleId: Int,
    @SerializedName("customerId")
    val customerId: Int,
    @SerializedName("serviceType")
    val serviceType: String,
    @SerializedName("appointmentTime")
    val appointmentTime: String? = null,
    @SerializedName("arrivalTime")
    val arrivalTime: String? = null,
    @SerializedName("startTime")
    val startTime: String? = null,
    @SerializedName("completeTime")
    val completeTime: String? = null,
    @SerializedName("staffId")
    val staffId: Int? = null,
    @SerializedName("currentMileage")
    val currentMileage: Double? = null,
    @SerializedName("faultDescription")
    val faultDescription: String? = null,
    @SerializedName("diagnosisResult")
    val diagnosisResult: String? = null,
    @SerializedName("serviceItems")
    val serviceItems: String? = null,
    @SerializedName("partsCost")
    val partsCost: Double? = 0.0,
    @SerializedName("laborCost")
    val laborCost: Double? = 0.0,
    @SerializedName("totalCost")
    val totalCost: Double? = 0.0,
    @SerializedName("status")
    val status: String,
    @SerializedName("paymentStatus")
    val paymentStatus: String,
    @SerializedName("remark")
    val remark: String? = null,
    @SerializedName("createTime")
    val createTime: String
) {
    enum class ServiceType(val displayName: String) {
        MAINTENANCE("保养维护"),
        REPAIR("维修服务"),
        BEAUTY("美容服务"),
        INSURANCE("保险代理");

        companion object {
            fun fromValue(value: String): ServiceType {
                return values().find { it.name.lowercase() == value } ?: MAINTENANCE
            }
        }
    }

    enum class Status(val displayName: String) {
        PENDING("待处理"),
        APPOINTED("已预约"),
        IN_PROGRESS("进行中"),
        COMPLETED("已完成"),
        CANCELLED("已取消");

        companion object {
            fun fromValue(value: String): Status {
                return values().find { it.name.lowercase() == value } ?: PENDING
            }
        }
    }

    val serviceTypeEnum: ServiceType
        get() = ServiceType.fromValue(serviceType)

    val statusEnum: Status
        get() = Status.fromValue(status)
}
