package com.jordanbot.autoride.parser

import com.jordanbot.autoride.model.RideRequest

class CareemParser : NotificationParser {
    override val packageName = "com.careem.adma"

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

        // Careem format examples: "رحلة جديدة - 2.5 د.أ", "New ride - 2.5 JOD"
        val priceRegex = """(\d+\.?\d*)\s*(JOD|د\.أ|دينار)""".toRegex()
        val minutesRegex = """(\d+)\s*(min|دقيقة|دقائق)""".toRegex()

        val fullText = "$title $text"

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

        minutesRegex.find(fullText)?.let {
            minutes = it.groupValues[1].toIntOrNull()
        }

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