﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace MappingCommon.PlacesApi
{
    //Disable the 'unused field' warning for these classes - fields will be assigned when deserialized by JSON.NET.
    #pragma warning disable 0649

    public class PlacesResult
    {
        [JsonIgnore]
        public double Latitude => Geometry.Location.Latitude;

        [JsonIgnore]
        public double Longitude => Geometry.Location.Longitude;

        [JsonIgnore]
        public string Address => Vicinity ?? FormattedAddress;

        [JsonProperty]
        public string Name;

        [JsonProperty]
        private string Vicinity;

        [JsonProperty("formatted_address")]
        private string FormattedAddress;

        [JsonProperty]
        private PlacesGeometry Geometry;

        [JsonProperty("place_id")]
        public string Id;

        [JsonProperty]
        public string Icon;

        public override string ToString()
        {
            return $"{Name}: \"{Address}\" ({Latitude}, {Longitude})";
        }
    }

    internal class PlacesGeometry
    {
        [JsonProperty]
        public PlacesLocation Location;
    }

    internal class PlacesLocation
    {
        [JsonProperty(PropertyName = "lat")]
        public double Latitude;

        [JsonProperty(PropertyName = "lng")]
        public double Longitude;
    }

    #pragma warning restore 0649
}
