using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Bellwether.Model
{
    public class SolarEnergyModel
    {
        public string Area { get; set; }
        public long Energy { get; set; }
        public long CO2EmissionSaved { get; set; }
        public long EquivalentTreesPlanted { get; set; }

        public static SolarEnergyModel Parse(SolarEnergyRawModel rawModel)
        {
            if (rawModel == null)
            {
                return new SolarEnergyModel();
            }
            if (!long.TryParse(rawModel.Energy, out var energy) ||
                !long.TryParse(rawModel.CO2EmissionSaved, out var co2EmissionSaved) ||
                !long.TryParse(rawModel.EquivalentTreesPlanted, out var equivalentTreesPlanted))
            {
                return new SolarEnergyModel();
            }
            return new SolarEnergyModel()
            {
                Area = rawModel.Area,
                Energy = energy,
                CO2EmissionSaved = co2EmissionSaved,
                EquivalentTreesPlanted = equivalentTreesPlanted
            };
        }
    }

    public class SolarEnergyRawModel
    {
        public string Area { get; set; }
        public string Energy { get; set; }
        public string CO2EmissionSaved { get; set; }
        public string EquivalentTreesPlanted { get; set; }
    }
}
