/**
 * 土壤质量评价类型定义
 */

export interface SoilIndicator {
  id: string;
  name: string;
  value: number;
  unit: string;
  optimalRange: {
    min: number;
    max: number;
  };
  score: number;
  status: 'excellent' | 'good' | 'moderate' | 'poor' | 'very_poor';
  weight: number;
  description: string;
}

export interface SoilQualityEvaluation {
  id: string;
  fieldId: string;
  fieldName: string;
  date: string;
  location: string;
  indicators: SoilIndicator[];
  overallScore: number;
  overallGrade: 'A' | 'B' | 'C' | 'D' | 'E';
  soilType: string;
  texture: string;
  drainage: 'excellent' | 'good' | 'moderate' | 'poor';
  fertility: 'high' | 'medium' | 'low';
  recommendations: SoilRecommendation[];
  evaluationNotes: string;
  evaluator: string;
  nextEvaluationDate: string;
}

export interface SoilRecommendation {
  category: 'fertilizer' | 'organic_matter' | 'ph_adjustment' | 'drainage' | 'crop_rotation' | 'other';
  priority: 'high' | 'medium' | 'low';
  title: string;
  description: string;
  actionItems: string[];
  expectedImprovement: number;
  timeframe: string;
  estimatedCost: number;
  costUnit: 'yuan_per_mu' | 'yuan_per_hectare' | 'yuan_total';
}

export interface SoilQualityHistory {
  date: string;
  overallScore: number;
  indicatorChanges: {
    indicatorId: string;
    indicatorName: string;
    previousValue: number;
    currentValue: number;
    change: number;
    trend: 'improving' | 'declining' | 'stable';
  }[];
  evaluation: SoilQualityEvaluation;
}

export interface SoilQualityStandard {
  region: string;
  soilType: string;
  indicators: {
    [key: string]: {
      optimalRange: { min: number; max: number };
      acceptableRange: { min: number; max: number };
      criticalRange: { min: number; max: number };
      weight: number;
    };
  };
}

export interface FertilizerRecommendation {
  nutrientType: 'nitrogen' | 'phosphorus' | 'potassium' | 'organic_matter' | 'micronutrients';
  currentLevel: number;
  targetLevel: number;
  deficit: number;
  recommendedAmount: number;
  unit: string;
  fertilizerOptions: {
    name: string;
    content: number;
    applicationRate: number;
    cost: number;
    timing: string;
  }[];
}

export interface SoilAnalysisForm {
  fieldId: string;
  sampleDate: string;
  sampleDepth: number;
  ph: number;
  organicMatter: number;
  nitrogen: number;
  phosphorus: number;
  potassium: number;
  calcium: number;
  magnesium: number;
  sulfur: number;
  iron: number;
  manganese: number;
  zinc: number;
  copper: number;
  boron: number;
  soilTexture: string;
  drainage: string;
  notes: string;
}

// 土壤质量等级定义
export const SOIL_QUALITY_GRADES = {
  A: { min: 90, max: 100, label: '优秀', color: '#22c55e', description: '土壤质量极佳，适合各种作物生长' },
  B: { min: 80, max: 89, label: '良好', color: '#84cc16', description: '土壤质量良好，适合大部分作物生长' },
  C: { min: 70, max: 79, label: '中等', color: '#eab308', description: '土壤质量中等，需要适当改良' },
  D: { min: 60, max: 69, label: '较差', color: '#f97316', description: '土壤质量较差，需要重点改良' },
  E: { min: 0, max: 59, label: '很差', color: '#ef4444', description: '土壤质量很差，需要全面改良' }
};

// 土壤指标定义
export const SOIL_INDICATORS = {
  ph: {
    id: 'ph',
    name: 'pH值',
    unit: '',
    optimalRange: { min: 6.0, max: 7.5 },
    weight: 0.15,
    description: '土壤酸碱度，影响养分有效性和微生物活动'
  },
  organicMatter: {
    id: 'organicMatter',
    name: '有机质',
    unit: '%',
    optimalRange: { min: 2.5, max: 5.0 },
    weight: 0.20,
    description: '土壤有机质含量，反映土壤肥力和结构'
  },
  nitrogen: {
    id: 'nitrogen',
    name: '全氮',
    unit: 'g/kg',
    optimalRange: { min: 1.0, max: 2.0 },
    weight: 0.15,
    description: '土壤氮素含量，植物生长的重要营养元素'
  },
  phosphorus: {
    id: 'phosphorus',
    name: '有效磷',
    unit: 'mg/kg',
    optimalRange: { min: 15, max: 30 },
    weight: 0.15,
    description: '土壤有效磷含量，促进植物根系发育和开花结果'
  },
  potassium: {
    id: 'potassium',
    name: '速效钾',
    unit: 'mg/kg',
    optimalRange: { min: 100, max: 200 },
    weight: 0.15,
    description: '土壤速效钾含量，提高植物抗逆性和产量'
  },
  calcium: {
    id: 'calcium',
    name: '交换性钙',
    unit: 'mg/kg',
    optimalRange: { min: 1000, max: 2000 },
    weight: 0.05,
    description: '土壤钙含量，调节土壤结构和植物细胞壁形成'
  },
  magnesium: {
    id: 'magnesium',
    name: '交换性镁',
    unit: 'mg/kg',
    optimalRange: { min: 200, max: 400 },
    weight: 0.05,
    description: '土壤镁含量，叶绿素合成的重要元素'
  },
  sulfur: {
    id: 'sulfur',
    name: '有效硫',
    unit: 'mg/kg',
    optimalRange: { min: 10, max: 30 },
    weight: 0.05,
    description: '土壤硫含量，蛋白质合成的重要元素'
  },
  iron: {
    id: 'iron',
    name: '有效铁',
    unit: 'mg/kg',
    optimalRange: { min: 5, max: 20 },
    weight: 0.025,
    description: '土壤铁含量，叶绿素合成必需元素'
  },
  manganese: {
    id: 'manganese',
    name: '有效锰',
    unit: 'mg/kg',
    optimalRange: { min: 2, max: 10 },
    weight: 0.025,
    description: '土壤锰含量，参与植物光合作用'
  },
  zinc: {
    id: 'zinc',
    name: '有效锌',
    unit: 'mg/kg',
    optimalRange: { min: 1, max: 5 },
    weight: 0.025,
    description: '土壤锌含量，植物生长素合成的必需元素'
  },
  copper: {
    id: 'copper',
    name: '有效铜',
    unit: 'mg/kg',
    optimalRange: { min: 0.5, max: 2 },
    weight: 0.025,
    description: '土壤铜含量，参与植物呼吸作用'
  },
  boron: {
    id: 'boron',
    name: '有效硼',
    unit: 'mg/kg',
    optimalRange: { min: 0.5, max: 2 },
    weight: 0.025,
    description: '土壤硼含量，植物开花结果必需元素'
  }
};

// 土壤类型定义
export const SOIL_TYPES = [
  { id: 'sandy_loam', name: '砂壤土', description: '排水良好，保肥能力中等' },
  { id: 'loam', name: '壤土', description: '质地适中，农业生产的理想土壤' },
  { id: 'clay_loam', name: '黏壤土', description: '保肥保水能力强，但排水较差' },
  { id: 'sandy', name: '砂土', description: '排水良好，但保肥能力差' },
  { id: 'clay', name: '黏土', description: '保肥保水能力强，通气性差' },
  { id: 'silt', name: '粉土', description: '肥力较高，但结构不稳定' }
];

// 土壤质地定义
export const SOIL_TEXTURES = [
  { id: 'coarse', name: '粗质地', description: '砂粒含量高，排水快' },
  { id: 'medium', name: '中等质地', description: '砂粒、粉粒、黏粒比例适中' },
  { id: 'fine', name: '细质地', description: '黏粒含量高，保水保肥能力强' }
];

// 排水等级定义
export const DRAINAGE_LEVELS = [
  { id: 'excellent', name: '优秀', description: '排水通畅，无积水现象' },
  { id: 'good', name: '良好', description: '排水较好，偶有短期积水' },
  { id: 'moderate', name: '中等', description: '排水一般，雨季有积水' },
  { id: 'poor', name: '较差', description: '排水困难，长期积水' }
];