using NetTopologySuite.Geometries;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Runtime.Serialization;
using System.Threading.Tasks;

namespace CarbonService.Models
{
    public class CarbonRequest
    {
        public Geometry geometry { get; set; }
        [Required]
        public int PostalCode { get; set; }
        public List<CropField> CropFields { get; set; }
    }

    public class CropField
    {
        [Required]
        public string Name { get; set; }
        [Required]
        public double Area { get; set; }
        [Required]
        public string SoilType { get; set; }
        [Required]
        public SoilProperty SoilProperty { get; set; }
        [Required]
        public List<HistoricalCropData> HistoricalCropData { get; set; }
        public List<GreenManure> GreenManures { get; set; }        
    }

    public class SoilProperty
    {
        public double? OM_Const { get; set; }
        public double? C_Const { get; set; }
        public string OM_Choice { get; set; }
        public double? Clay_Content { get; set; }
        public bool? Depth10 { get; set; }
        public int? Depth { get; set; }
    }

    public class OrgManureApplied
    {
        double? yield;

        [Required]
        public string Crop { get; set; }
        public List<OrganicManureType> OrganicManures { get; set; }
        public double? CropYield { get { return (int?)yield; } set { yield = value; } }
        public bool CropRes { get; set; }
        public string Irrigation { get; set; }
    }

    public class OrganicManureType
    {
        [Required]
        public string Type { get; set; }
        [Required]
        public double Quantity { get; set; }
    }

    public class HistoricalCropData
    {
        [Required]
        public int Year { get; set; }
        [Required]
        public List<OrgManureApplied> Crops { get; set; }
    }

    public class GreenManure
    {
        [Required]
        public int Year { get; set; }
        [Required]
        public List<GreenManureType> GreenManureTypes { get; set; }
    }

    public class GreenManureType
    {
        [Required]
        public string Type { get; set; }

        [JsonConverter(typeof(StringEnumConverter))]
        public Quality Quality { get; set; }
    }

    public enum Quality
    {
        [EnumMember(Value = "Goed")]
        Good,
        [EnumMember(Value = "Matig")]
        Average,
        [EnumMember(Value = "Slecht")]
        Bad
    }
}
