package com.prodhack.moscow2025.data.data_providers.local_db.entities

import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey
import com.prodhack.moscow2025.domain.models.ExperienceType
import com.prodhack.moscow2025.domain.models.ResumeModel

@Entity(tableName = "resumes")
data class ResumeEntity(
	@PrimaryKey(autoGenerate = false)
	val id: String,
	@ColumnInfo("experience_type")
	val experienceType: String,
	@ColumnInfo("about_me")
	val aboutMe: String,
	@ColumnInfo("key_skills")
	val keySkills: String,
	val position: String,
	@ColumnInfo("from_salary")
	val fromSalary: Float?,
	@ColumnInfo("to_salary")
	val toSalary: Float?,
	@ColumnInfo("recommended_skills")
	val recommendedSkills: String,
	val city: String,
	val experience: String, // Store as JSON string, requires TypeConverter
	val education: String, // Store as JSON string, requires TypeConverter
	val projects: String // Store as JSON string, requires TypeConverter
) {
	fun mapToDomain(): ResumeModel = ResumeModel(
		id = id,
		position = position,
		about = aboutMe,
		experienceType = ExperienceType.valueOf(experienceType),
		skills = keySkills.split("|"),
		prediction = if (fromSalary == null && toSalary == null) null else Pair(
			fromSalary,
			toSalary
		),
		recommendedSkills = if (recommendedSkills.isBlank()) emptyList() else recommendedSkills.split("|").filter { it.isNotBlank() },
		city = city,
		experience = JsonTypeConverters.toWorkExperienceList(experience),
		education = JsonTypeConverters.toEducationList(education),
		projects = JsonTypeConverters.toProjectList(projects)
	)
}
