package com.rugvedsarika.areacalc

import android.content.Context

enum class AreaUnit(val nameResId: Int, val toSquareMeters: Double) {
    SQUARE_METER(R.string.unit_sq_meter, 1.0),
    SQUARE_KILOMETER(R.string.unit_sq_km, 1_000_000.0),
    SQUARE_FOOT(R.string.unit_sq_foot, 0.092903),
    SQUARE_YARD(R.string.unit_sq_yard, 0.836127),
    ACRE(R.string.unit_acre, 4046.86),
    HECTARE(R.string.unit_hectare, 10_000.0),
    ARE(R.string.unit_are, 100.0),
    CENT(R.string.unit_cent, 40.4686),
    
    // Indian Land Units (Average/Standard values)
    BIGHA(R.string.unit_bigha, 2529.29),
    GUNTHA(R.string.unit_guntha, 101.17),
    ROPANI(R.string.unit_ropani, 508.72),
    KATHA(R.string.unit_katha, 126.44),
    KANAL(R.string.unit_kanal, 505.86);

    companion object {
        fun convert(value: Double, from: AreaUnit, to: AreaUnit): Double {
            val valueInSqMeters = value * from.toSquareMeters
            return valueInSqMeters / to.toSquareMeters
        }
        
        fun getNames(context: Context): List<String> {
            return values().map { context.getString(it.nameResId) }
        }
        
        fun fromDisplayName(context: Context, name: String): AreaUnit? {
            return values().find { context.getString(it.nameResId) == name }
        }
    }
}
