// 分类字典类型定义
export interface CategoryDictionary {
  id: string;
  code: string;
  name: string;
  type: string; // 分类类型：industry, equipment, crop等
  parentId?: string;
  level: number;
  sortOrder: number;
  description?: string;
  isActive: boolean;
  children?: CategoryDictionary[];
  createdAt: string;
  updatedAt: string;
}

export type CategoryType = 'industry' | 'equipment' | 'crop' | 'operation' | 'other';

// 分类表单数据
export interface CategoryFormData {
  code: string;
  name: string;
  type: string;
  description: string;
  sortOrder: number;
  isActive: boolean;
}

// 分类操作类型
export type CategoryAction =
  | { type: 'SET_CATEGORIES'; payload: CategoryDictionary[] }
  | { type: 'ADD_CATEGORY'; payload: CategoryDictionary }
  | { type: 'UPDATE_CATEGORY'; payload: { id: string; updates: Partial<CategoryDictionary> } }
  | { type: 'DELETE_CATEGORY'; payload: string }
  | { type: 'SET_SEARCH_KEYWORD'; payload: string }
  | { type: 'SET_TYPE_FILTER'; payload: string }
  | { type: 'TOGGLE_EXPAND'; payload: string }
  | { type: 'SET_DIALOG_STATE'; payload: { open: boolean; editing?: CategoryDictionary; parent?: CategoryDictionary | null } }
  | { type: 'SET_FORM_DATA'; payload: Partial<CategoryFormData> };

// 分类状态
export interface CategoryState {
  categories: CategoryDictionary[];
  searchKeyword: string;
  typeFilter: string;
  expandedIds: Set<string>;
  dialogState: {
    open: boolean;
    editing?: CategoryDictionary;
    parent?: CategoryDictionary | null;
  };
  formData: CategoryFormData;
}