export enum CustomFieldType {
  Text = 0,
  Number = 1,
  Date = 2,
  Boolean = 3,
  Select = 4,
  MultiSelect = 5,
  TextArea = 6,
  Color = 7,
  Url = 8,
  Email = 9
}

export interface CustomFieldDefinition {
  id: number;
  entityName: string;
  fieldName: string;
  label: string;
  type: CustomFieldType;
  isRequired: boolean;
  defaultValue?: string;
  optionsJson?: string;
  sortOrder: number;
  description?: string;
  isActive: boolean;
  validationRegex?: string;
  placeholder?: string;
}

export interface CustomFieldValues {
  [key: string]: any;
}

export const entityNames: Record<string, string> = {
  Client: "Clienti",
  Article: "Articoli",
  Event: "Eventi",
  WarehouseArticle: "Articoli Magazzino",
  WarehouseLocation: "Magazzini",
  Resource: "Risorse"
};

export const entityIcons: Record<string, string> = {
  Client: "People",
  Article: "Restaurant",
  Event: "Event",
  WarehouseArticle: "Inventory",
  WarehouseLocation: "Warehouse",
  Resource: "Badge"
};

export const fieldTypeNames: Record<number, string> = {
  [CustomFieldType.Text]: "Testo",
  [CustomFieldType.Number]: "Numero",
  [CustomFieldType.Date]: "Data",
  [CustomFieldType.Boolean]: "Booleano",
  [CustomFieldType.Select]: "Selezione",
  [CustomFieldType.MultiSelect]: "Selezione Multipla",
  [CustomFieldType.TextArea]: "Area Testo",
  [CustomFieldType.Color]: "Colore",
  [CustomFieldType.Url]: "URL",
  [CustomFieldType.Email]: "Email"
};

export const groupByEntity = (fields: CustomFieldDefinition[]) => {
  return fields.reduce((acc, field) => {
    const entity = field.entityName;
    if (!acc[entity]) {
      acc[entity] = [];
    }
    acc[entity].push(field);
    return acc;
  }, {} as Record<string, CustomFieldDefinition[]>);
};
