package com.isidroid.c23.data.mapper

import android.content.Context
import com.isidroid.c23.domain.dto.PrintJobListItem
import com.isidroid.c23.ext.getPrintJobStatus
import com.isidroid.c23.ext.getPrintJobStatusColor
import com.isidroid.job.model.PrintJob
import com.isidroid.rendering.constant.printSizeName
import com.isidroid.spot.model.RichSpot
import java.io.File

fun PrintJob.createListItem(context: Context, richSpot: RichSpot?): PrintJobListItem {
    val profile = richSpot?.printProfiles?.find { it.id == profileId }
    return PrintJobListItem(
        id = id,
        spotCode = richSpot?.spot?.code,
        spotName = richSpot?.spot?.name ?: "Deleted spot",
        spotAddress = richSpot?.spot?.address ?: "Deleted spot",
        cost = cost,
        paperInfo = printSize.printSizeName,
        isColor = profile?.grayscale != true,
        statusColor = getPrintJobStatusColor(status),
        comment = comment,
        copies = copies,
        cover = sourceFiles?.firstOrNull()?.takeIf { File(it).exists() },
        statusName = context.getString(getPrintJobStatus(status)),
        accessCode = accessCode.orEmpty(),
        createdAt = createdAt,
        profileName = profile?.name,
        profileCost = profile?.cost
    )
}