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

namespace CarbonLib.Carbon.Models
{
    public class FarmMapsCarbonRequest
    {
        public string ModelYear { get; set; }
        public string ScenarioName { get; set; }
        public int PostalCode { get; set; }

        public List<CropFieldFarmMaps> CropFields { get; set; }

        //added
        public int CalculateUntil { get; set; }

        [JsonIgnore]
        public int CalculateFrom { get; set; } = 0;
    }

    public class CropFieldFarmMaps
    {
        [Required]
        public string Name { get; set; }
        [Required]
        public double Area { get; set; }
        [Required]
        public string SoilType { get; set; }
        public string SoilTypeDefault { get; set; }
        [Required]
        public SoilPropertyFarmMaps SoilProperty { get; set; }
        [Required]
        public List<HistoricalCropDataFarmMaps> HistoricalCropData { get; set; }
    }

    public class HistoricalCropDataFarmMaps
    {
        [Required]
        public int Year { get; set; }
        [Required]
        public List<CropData> Crops { get; set; }
        public List<GreenManureTypeFarmMaps> GreenManures { get; set; }
        public bool Rotation { get; set; }
        public string Irrigations { get; set; }

        public HistoricalCropDataFarmMaps DeepCopy()
        {
            HistoricalCropDataFarmMaps other = (HistoricalCropDataFarmMaps)this.MemberwiseClone();
            return other;
        }
    }

    public class CropData
    {
        double? yield;

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

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

    public class SoilPropertyFarmMaps
    {
        public double? OM_Const { get; set; }
        public double? C_Const { get; set; }
        public double? OM_ConstDefault { get; set; }
        public string OM_Choice { get; set; }
        public double? Clay_Content { get; set; }
        public double? Clay_ContentDefault { get; set; }
        public bool Depth10 { get; set; }
        public int? Depth { get; set; }        
        [JsonIgnore]
        public List<OrganicMatterFarmMaps> OrganicMatters { get; set; }
    }

    public class OrganicMatterFarmMaps
    {
        public int Year { get; set; }
        public double OrganicMatter { get; set; }
    }

    public class GreenManureTypeFarmMaps
    {
        public string CropCode { get; set; }
        [JsonConverter(typeof(StringEnumConverter))]
        public QualityFarmMaps? Quality { get; set; }
    }

    public enum QualityFarmMaps
    {
        [EnumMember(Value = "Goed")]
        Good = 1,
        [EnumMember(Value = "Matig")]
        Average = 2,
        [EnumMember(Value = "Slecht")]
        Bad = 3
    }
}
