package es.verdnatura.presentation.view.feature.delivery.model

import android.os.Build
import androidx.annotation.RequiresApi
import androidx.room.Entity
import androidx.room.PrimaryKey
import androidx.room.TypeConverters
import com.google.gson.annotations.SerializedName
import es.verdnatura.db.MapTypeConverter
import es.verdnatura.domain.isoToString
import java.io.Serializable
import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale

class FreeLanceDeliveryInfoList(
    var list: List<DeliveryInfo> = listOf()
)

class CompanyInfoList(
    var list: List<DeliveryInfo> = listOf()
)

class DeliveryInfo(
    var name: String? = null,
    var street: String? = null,
    var city: String? = null,
    var nif: String? = null,
    var postCode: String? = null
)

class Expeditions(
    val expeditions: List<ExpeditionSalix> = listOf()
)

class ExpeditionSalix(
    val expeditionFk: Int,
    val stateCode: String?
)

class ExpeditionInfoList(
    var list: List<ExpeditionInfoLog> = listOf()
)

data class ExpeditionInfoLog(
    var state: String,
    var name: String,
    //var created: String,
    var routeSalix: RouteSalix
) {
    var created: String = ""
        @RequiresApi(Build.VERSION_CODES.O)
        get() {
            return field.isoToString()
        }
}
class RouteDeliveryList(
    var list: List<RouteDelivery> = listOf()
)

data class RouteSalix(
    var agencyMode: AgencyModeSalix,
    var created: String?
)

data class AgencyModeSalix(
    val agency: Agency
)

data class Agency(
    var name: String?
)

class TicketSalix(
    var id: Int,
    var routeFk: Int?,
    var route: RouteSalix,

    )

class RouteDelivery(
    var id: Int,
    //var created: String,
    var name: String?,
    var ticket: TicketSalix,

    ) {
    var created: String = ""
    @RequiresApi(Build.VERSION_CODES.O)
    get(){
        return field.isoToString(returnOnlyDate = true)
    }

}

class
Expedition(
    var id: Int
)

class ExpeditionList(
    var list: List<ExpeditionInfoLoadUnload> = listOf(),
)

@Entity(tableName = "expedition")
class ExpeditionInfoLoadUnload(
    @PrimaryKey var id: Int,
    var ticketFk: Int,
    var routeFk: Int,
    var addressFk: Int,
    var itemPackingTypeConcat: String?,
    var city: String,
    var street: String,
    var code: String?,
    var nickname: String,
    var postalCode: Int,
) : Serializable

@Entity(tableName = "expeditionPending")
class ExpeditionInfoPending(
    @PrimaryKey var id: Int,
    var ticketFk: Int,
    var routeFk: Int,
    var addressFk: Int,
    var itemPackingTypeConcat: String?,
    var city: String,
    var street: String,
    var code: String?,
    var nickname: String,
    var postalCode: Int

) : Serializable

class ExpeditionSummaryList(
    var list: List<ExpeditionInfoSummary> = listOf()
)

class ExpeditionInfoSummary(
    var routeFk: Int,
    var addressFk: Int,
    var itemPackingType: String?,
    var total: Int,
    var delivery: Int,
    var lost: Int,
    var delivered: Int
)

class RouteList(
    var list: MutableList<RouteInfo> = mutableListOf()
)

@Entity(tableName = "routesLoaded")
class RouteLoaded(
    @PrimaryKey var id: Long,
    var created: String
)

@Entity(tableName = "routes")
class RouteInfo(
    @PrimaryKey var id: Long,
    @SerializedName(value = "driver", alternate = ["workerUserName"])
    var driver: String?,
    var hour: String?,
    @TypeConverters(MapTypeConverter::class) var created: Date,
    var m3: Double,
    @SerializedName(value = "numberPlate", alternate = ["vehiclePlateNumber"])
    var numberPlate: String?,
    @SerializedName(value = "name", alternate = ["agencyName"])
    var name: String,
    var kmStart: Long,
    var kmEnd: Long,
    var started: String,
    var finished: String,
    var header: Boolean = false,
    //tarea 5867
    var email: String? = null
) : Serializable {
    override fun toString(): String {
        return "$driver$id$name$numberPlate$m3$created$hour$"
    }
}

val dateFormat = SimpleDateFormat("yyyy-MM-dd", Locale.getDefault())