// ─── Elemental Conversion Disciplines (Base + Utility) ─────────────────────────
// One discipline per mana type that converts raw mana into that element.
// All are BASE attunement so they are available to every role once the element is unlocked.
//
// NEW MODEL: Disciplines contribute to conversion_{element} stat bonus.
// The unified conversion-rates.ts calculator handles rate computation.
// Mana drain is applied from the target mana type pool each tick.

import { DisciplinesAttunementType } from '../../types/disciplines';
import type { DisciplineDefinition } from '../../types/disciplines';

interface BaseConversionConfig {
  id: string;
  name: string;
  manaType: string;
  cost: number;
  /** Base conversion rate (per hour) before XP scaling */
  conversionRate?: number;
  difficultyFactor?: number;
  scalingFactor?: number;
  drainBase?: number;
}

function createManaConversionDiscipline(cfg: BaseConversionConfig): DisciplineDefinition {
  const rate = cfg.conversionRate ?? 0.5;
  const diff = cfg.difficultyFactor ?? 120;
  const scale = cfg.scalingFactor ?? 60;
  const drain = cfg.drainBase ?? 1.5;
  const nameLower = cfg.name.toLowerCase();

  return {
    id: cfg.id,
    name: `${cfg.name} Mana Conversion Speed`,
    attunement: DisciplinesAttunementType.BASE,
    manaType: cfg.manaType as DisciplineDefinition['manaType'],
    baseCost: cfg.cost,
    description: `Convert raw mana into ${nameLower} mana over time.`,
    statBonus: {
      stat: `conversion_${cfg.manaType}` as DisciplineDefinition['statBonus']['stat'],
      baseValue: rate,
      label: `${cfg.name} Conversion/hr`,
    },
    difficultyFactor: diff,
    scalingFactor: scale,
    drainBase: drain,
    conversionRate: rate,
    sourceManaTypes: ['raw' as DisciplineDefinition['manaType']],
    requires: [cfg.manaType],
    perks: [
      {
        id: `${cfg.id}-1`,
        type: 'once',
        threshold: 100,
        value: 0,
        description: `+${rate} ${cfg.name} Conversion/hr`,
        bonus: { stat: `conversion_${cfg.manaType}`, amount: rate },
      },
      {
        id: `${cfg.id}-inf`,
        type: 'infinite',
        threshold: 300,
        value: 100,
        description: `Every 100 XP: +${rate * 0.5} ${cfg.name} Conversion/hr`,
        bonus: { stat: `conversion_${cfg.manaType}`, amount: rate * 0.5 },
      },
    ],
  };
}

export const elementalRegenDisciplines: DisciplineDefinition[] = [
  // ── Base Elements (distance 1, rate 0.5/hr) ──────────────────────────────
  createManaConversionDiscipline({ id: 'regen-fire',  name: 'Fire',  manaType: 'fire',  cost: 8 }),
  createManaConversionDiscipline({ id: 'regen-water', name: 'Water', manaType: 'water', cost: 8 }),
  createManaConversionDiscipline({ id: 'regen-air',   name: 'Air',   manaType: 'air',   cost: 8 }),
  createManaConversionDiscipline({ id: 'regen-earth', name: 'Earth', manaType: 'earth', cost: 8 }),
  createManaConversionDiscipline({ id: 'regen-light', name: 'Light', manaType: 'light', cost: 8 }),
  createManaConversionDiscipline({ id: 'regen-dark',  name: 'Dark',  manaType: 'dark',  cost: 8 }),
  createManaConversionDiscipline({ id: 'regen-death', name: 'Death', manaType: 'death', cost: 8 }),

  // ── Utility Element (distance 1, rate 0.4/hr) ────────────────────────────
  createManaConversionDiscipline({
    id: 'regen-transference',
    name: 'Transference',
    manaType: 'transference',
    cost: 6,
    conversionRate: 0.4,
    difficultyFactor: 100,
    scalingFactor: 50,
    drainBase: 1,
  }),
];
