package com.fieldlabel.collector.data.local

import androidx.room.Entity
import androidx.room.PrimaryKey
import com.fieldlabel.collector.domain.model.SpecimenPhoto
import java.time.LocalDateTime

@Entity(tableName = "specimen_photos")
data class SpecimenPhotoEntity(
    @PrimaryKey val id: String,
    val filePath: String,
    val locationId: String,
    val specimenId: String?,          // null = 地点全体に紐づく
    val takenAt: String,              // LocalDateTime.toString() で保存
    val mediaType: String = "photo"   // "photo" | "video" | "audio"
) {
    fun toDomain() = SpecimenPhoto(
        id         = id,
        filePath   = filePath,
        locationId = locationId,
        specimenId = specimenId,
        takenAt    = LocalDateTime.parse(takenAt),
        mediaType  = mediaType
    )

    companion object {
        fun fromDomain(p: SpecimenPhoto) = SpecimenPhotoEntity(
            id         = p.id,
            filePath   = p.filePath,
            locationId = p.locationId,
            specimenId = p.specimenId,
            takenAt    = p.takenAt.toString(),
            mediaType  = p.mediaType
        )
    }
}
