/**
 * Types per il sistema di codici automatici
 */

export interface AutoCodeDto {
  id: number;
  entityCode: string;
  entityName: string;
  prefix: string | null;
  pattern: string;
  lastSequence: number;
  resetSequenceYearly: boolean;
  resetSequenceMonthly: boolean;
  lastResetYear: number | null;
  lastResetMonth: number | null;
  isEnabled: boolean;
  isReadOnly: boolean;
  moduleCode: string | null;
  description: string | null;
  sortOrder: number;
  exampleCode: string;
  createdAt: string | null;
  updatedAt: string | null;
}

export interface AutoCodeUpdateDto {
  prefix?: string | null;
  pattern?: string | null;
  resetSequenceYearly?: boolean;
  resetSequenceMonthly?: boolean;
  isEnabled?: boolean;
  isReadOnly?: boolean;
  description?: string | null;
}

export interface GenerateCodeResponse {
  code: string;
  entityCode: string;
  isPreview?: boolean;
}

export interface ResetSequenceRequest {
  newValue?: number;
}

export interface CheckUniqueResponse {
  isUnique: boolean;
  code: string;
  entityCode: string;
}

export interface PlaceholderInfo {
  placeholder: string;
  description: string;
  example: string;
}

/**
 * Raggruppa le configurazioni per modulo
 */
export function groupByModule(configs: AutoCodeDto[]): Record<string, AutoCodeDto[]> {
  return configs.reduce((acc, config) => {
    const module = config.moduleCode || "core";
    if (!acc[module]) {
      acc[module] = [];
    }
    acc[module].push(config);
    return acc;
  }, {} as Record<string, AutoCodeDto[]>);
}

/**
 * Nomi visualizzati per i moduli
 */
export const moduleNames: Record<string, string> = {
  core: "Sistema Base",
  warehouse: "Magazzino",
  purchases: "Acquisti",
  sales: "Vendite",
  production: "Produzione",
  quality: "Qualità",
};

/**
 * Icone per i moduli (nomi MUI icons)
 */
export const moduleIcons: Record<string, string> = {
  core: "Settings",
  warehouse: "Warehouse",
  purchases: "ShoppingCart",
  sales: "PointOfSale",
  production: "Factory",
  quality: "VerifiedUser",
};
