package com.jordanbot.autoride.parser

import com.jordanbot.autoride.model.RideRequest

class JeenyParser : NotificationParser {
    override val packageName = "me.com.easytaxista"

    override fun parse(title: String, text: String): RideRequest? {
        var price: Double? = null
        var distance: Double? = null

        val priceRegex = """(\d+\.?\d*)\s*(JOD|د\.أ)""".toRegex()
        // Jeeny often shows distance in km instead of minutes
        val distanceRegex = """(\d+\.?\d*)\s*(km|كم)""".toRegex()

        val fullText = "$title $text"

        priceRegex.find(fullText)?.let {
            price = it.groupValues[1].toDoubleOrNull()
        }

        distanceRegex.find(fullText)?.let {
            distance = it.groupValues[1].toDoubleOrNull()
        }

        return RideRequest(
            appPackage = packageName,
            priceJod = price,
            minutesAway = null,
            distanceKm = distance,
            title = title,
            text = text
        )
    }
}
