package kr.lunaticbum.back.lun.model


import kotlin.math.atan2
import kotlin.math.cos
import kotlin.math.sin
import kotlin.math.sqrt

//
//class PlaceGoogle {
//
//    var results : ArrayList<Place> = arrayListOf()
//}
//class Place {
//    var name : String? = ""
//
//    var price_level : String? = null
//
//    var rating : String? = null
//
////    var reviews : ArrayList<PlaceReview>? = null
//
//    var user_ratings_total : String? = null
//
//    var geometry : PlaceGeometry? = null
//
//    var distance : Double? = 0.0
//
//    var place_id : String? = null
//
//    fun getDistane(currentLat : Double, currentLng : Double) : Double {
//        distance = calculateDistance(currentLat, currentLng, geometry!!.location!!.lat, geometry!!.location!!.lng)
//        return distance ?: 0.0
//    }
//
//    override fun toString(): String = "상호 : ${name}\n 총 리뷰수: ${user_ratings_total}\n평점 : \n${rating}\n거리 : \n${distance}\n링크 열기: https://www.google.com/maps/search/?api=1&query=${geometry!!.location!!.lat}%2C${geometry!!.location!!.lng}&query_place_id=${place_id}"
//
//}
//class PlaceGeometry {
//    var location : PlaceLocation? = null
//}
//class PlaceLocation {
//    var lat  : Double = 0.0//37.3890078,
//    var lng  : Double = 0.0//126.9510394
//}
//class PlaceReview {
//    var author_name : String? = null
//    var rating : String? = null
//    var relative_time_description : String? = null
//    var time : String? = null
//    var author_url : String? = null
//    var language : String? = null
//    var original_language : String? = null
//    var profile_photo_url : String? = null
//    var text : String? = null
//    var translated : String? = null
//}

const val EARTH_RADIUS = 6371.0 // 지구 반지름 (km)

fun calculateDistance(lat1: Double, lon1: Double, lat2: Double, lon2: Double): Double {
    val dLat = Math.toRadians(lat2 - lat1)
    val dLon = Math.toRadians(lon2 - lon1)

    val a = sin(dLat / 2) * sin(dLat / 2) +
            cos(Math.toRadians(lat1)) * cos(Math.toRadians(lat2)) * sin(dLon / 2) * sin(dLon / 2)

    val c = 2 * atan2(sqrt(a), sqrt(1 - a))

    return EARTH_RADIUS * c // km 단위 거리 반환
}

// import com.fasterxml.jackson.databind.ObjectMapper; // version 2.11.1
// import com.fasterxml.jackson.annotation.JsonProperty; // version 2.11.1
/* ObjectMapper om = new ObjectMapper();
Root root = om.readValue(myJsonString, Root.class); */
class GPGeometry {
    var location: GPLocation? = null
    var viewport: GPViewport? = null
}

class GPLocation {
    var lat: Double = 0.0
    var lng: Double = 0.0
}

class GPNortheast {
    var lat: Double = 0.0
    var lng: Double = 0.0
}

class GPOpeningHours {
    var open_now: Boolean = false
}

class GPPhoto {
    var height: Int = 0
    var html_attributions: ArrayList<String>? = null
    var photo_reference: String? = null
    var width: Int = 0
}

class GPPlusCode {
    var compound_code: String? = null
    var global_code: String? = null
}

class GPResult {
    var business_status: String? = null
    var geometry: GPGeometry? = null
    var icon: String? = null
    var icon_background_color: String? = null
    var icon_mask_base_uri: String? = null
    var name: String? = null
    var opening_hours: GPOpeningHours? = null
    var photos: ArrayList<GPPhoto>? = null
    var place_id: String? = null
    var plus_code: GPPlusCode? = null
    var price_level: Int = 0
    var rating: Double = 0.0
    var reference: String? = null
    var scope: String? = null
    var types: ArrayList<String>? = null
    var user_ratings_total: Int = 0
    var vicinity: String? = null
    var permanently_closed: Boolean = false
    var distance : Double = 0.0
        fun getDistane(currentLat : Double, currentLng : Double) : Double {
        distance = calculateDistance(currentLat, currentLng, geometry!!.location!!.lat, geometry!!.location!!.lng)
        return distance ?: 0.0
    }

    override fun toString(): String = "상호 : ${name}\n 총 리뷰수: ${user_ratings_total}\n평점 : \n${rating}\n거리 : \n${distance}\n링크 열기: https://www.google.com/maps/search/?api=1&query=${geometry!!.location!!.lat}%2C${geometry!!.location!!.lng}&query_place_id=${place_id}"
}

class GPlace {
    var error_message : String? = null
    var html_attributions: ArrayList<Any>? = null
    var next_page_token: String? = null
    var results: ArrayList<GPResult>? = null
    var status: String? = null
}

class GPSouthwest {
    var lat: Double = 0.0
    var lng: Double = 0.0
}

class GPViewport {
    var northeast: GPNortheast? = null
    var southwest: GPSouthwest? = null
}

