package com.example.myapplication.database.entities.model

import androidx.room.ColumnInfo
import org.threeten.bp.LocalDateTime
import org.threeten.bp.format.DateTimeFormatter

data class ItemFromBike(
    @ColumnInfo(name = "item_uid")
    val uid: Int,
    @ColumnInfo(name = "date_time")
    val dateTime: LocalDateTime,
    val weight: Double,
    @ColumnInfo(name = "available_count")
    var availableCount: Int,
    @ColumnInfo(name = "bike_id")
    val bikeId: Int,
) {
    override fun equals(other: Any?): Boolean {
        if (this === other) return true
        if (javaClass != other?.javaClass) return false
        other as ItemFromBike
        if (uid != other.uid) return false
        val dateFormatter = DateTimeFormatter.ofPattern("yyyy")
        if (dateFormatter.format(dateTime) != dateFormatter.format(other.dateTime)) return false
        if (weight != other.weight) return false
        if (availableCount != other.availableCount) return false
        if (bikeId != other.bikeId) return false
        return true
    }

    override fun hashCode(): Int {
        var result = uid
        result = 31 * result + dateTime.hashCode()
        result = 31 * result + weight.hashCode()
        result = 31 * result + availableCount.hashCode()
        result = 31 * result + bikeId.hashCode()
        return result
    }
}

fun ItemFromBike.toItem(): Item = Item (
    uid,
    dateTime,
    weight,
    availableCount,
    bikeId
)