package com.pixelized.desktop.lwa.ui.screen.admin.common.tag

import com.pixelized.shared.lwa.model.tag.Tag
import java.text.Collator

class GMTagFactory {

    fun convertToGMTagItemUio(
        tags: Collection<Tag>,
        selectedTagIds: List<String>,
    ): List<GMTagUio> {
        return tags
            .map { tag ->
                GMTagUio(
                    id = tag.id,
                    label = tag.label,
                    highlight = selectedTagIds.contains(tag.id),
                    meta = tag.meta,
                )
            }
            .sortedWith(
                comparator = compareBy(Collator.getInstance()) { it.label }
            )
    }

    fun convertToGMTagItemUio(
        tags: Collection<Tag>,
        selectedTagId: String?,
    ): List<GMTagUio> {
        return tags
            .map { tag ->
                GMTagUio(
                    id = tag.id,
                    label = tag.label,
                    highlight = tag.id == selectedTagId,
                    meta = tag.meta,
                )
            }
            .sortedWith(
                comparator = compareBy(Collator.getInstance()) { it.label }
            )
    }

    fun convertToGMTagItemUio(
        tag: Tag,
        selectedTagId: String?,
    ): GMTagUio {
        return GMTagUio(
            id = tag.id,
            label = tag.label,
            highlight = tag.id == selectedTagId,
            meta = tag.meta,
        )
    }
}