// ─── Elemental Conversion Disciplines (Composite + Exotic) ──────────────────────
// Conversion disciplines for composite and exotic mana types.
// 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 AdvancedConversionConfig {
  id: string;
  name: string;
  manaType: DisciplineDefinition['manaType'];
  cost: number;
  description: string;
  conversionRate: number;
  difficultyFactor: number;
  scalingFactor: number;
  drainBase: number;
  sourceManaTypes: DisciplineDefinition['manaType'][];
  infiniteThreshold?: number;
}

function createAdvancedConversionDiscipline(cfg: AdvancedConversionConfig): DisciplineDefinition {
  const nameLower = cfg.name.toLowerCase();
  const infThreshold = cfg.infiniteThreshold ?? 400;

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

export const elementalRegenAdvancedDisciplines: DisciplineDefinition[] = [
  // ── Composite Elements (distance 2, rate 0.35/hr) ────────────────────────
  createAdvancedConversionDiscipline({
    id: 'regen-metal',
    name: 'Metal',
    manaType: 'metal',
    cost: 12,
    description: 'Convert raw mana + fire mana + earth mana into metal mana over time.',
    conversionRate: 0.35,
    difficultyFactor: 160,
    scalingFactor: 80,
    drainBase: 2,
    sourceManaTypes: ['raw', 'fire', 'earth'],
  }),
  createAdvancedConversionDiscipline({
    id: 'regen-sand',
    name: 'Sand',
    manaType: 'sand',
    cost: 12,
    description: 'Convert raw mana + earth mana + water mana into sand mana over time.',
    conversionRate: 0.35,
    difficultyFactor: 160,
    scalingFactor: 80,
    drainBase: 2,
    sourceManaTypes: ['raw', 'earth', 'water'],
  }),
  createAdvancedConversionDiscipline({
    id: 'regen-lightning',
    name: 'Lightning',
    manaType: 'lightning',
    cost: 12,
    description: 'Convert raw mana + fire mana + air mana into lightning mana over time.',
    conversionRate: 0.35,
    difficultyFactor: 160,
    scalingFactor: 80,
    drainBase: 2,
    sourceManaTypes: ['raw', 'fire', 'air'],
  }),
  createAdvancedConversionDiscipline({
    id: 'regen-frost',
    name: 'Frost',
    manaType: 'frost',
    cost: 12,
    description: 'Convert raw mana + air mana + water mana into frost mana over time.',
    conversionRate: 0.35,
    difficultyFactor: 160,
    scalingFactor: 80,
    drainBase: 2,
    sourceManaTypes: ['raw', 'air', 'water'],
  }),
  // ── Composite Elements (distance 2, rate 0.30/hr) ────────────────────────
  createAdvancedConversionDiscipline({
    id: 'regen-blackflame',
    name: 'BlackFlame',
    manaType: 'blackflame',
    cost: 14,
    description: 'Convert raw mana + dark mana + fire mana into blackflame mana over time.',
    conversionRate: 0.3,
    difficultyFactor: 170,
    scalingFactor: 85,
    drainBase: 2,
    sourceManaTypes: ['raw', 'dark', 'fire'],
  }),
  createAdvancedConversionDiscipline({
    id: 'regen-radiantflames',
    name: 'Radiant Flames',
    manaType: 'radiantflames',
    cost: 14,
    description: 'Convert raw mana + light mana + fire mana into radiant flames mana over time.',
    conversionRate: 0.3,
    difficultyFactor: 170,
    scalingFactor: 85,
    drainBase: 2,
    sourceManaTypes: ['raw', 'light', 'fire'],
  }),
  createAdvancedConversionDiscipline({
    id: 'regen-miasma',
    name: 'Miasma',
    manaType: 'miasma',
    cost: 14,
    description: 'Convert raw mana + air mana + death mana into miasma mana over time.',
    conversionRate: 0.3,
    difficultyFactor: 170,
    scalingFactor: 85,
    drainBase: 2,
    sourceManaTypes: ['raw', 'air', 'death'],
  }),
  createAdvancedConversionDiscipline({
    id: 'regen-shadowglass',
    name: 'Shadow Glass',
    manaType: 'shadowglass',
    cost: 15,
    description: 'Convert raw mana + earth mana + dark mana into shadow glass mana over time.',
    conversionRate: 0.3,
    difficultyFactor: 170,
    scalingFactor: 85,
    drainBase: 2,
    sourceManaTypes: ['raw', 'earth', 'dark'],
  }),

  // ── Exotic Elements (distance 3, rate 0.25/hr) ──────────────────────────
  createAdvancedConversionDiscipline({
    id: 'regen-crystal',
    name: 'Crystal',
    manaType: 'crystal',
    cost: 18,
    description: 'Convert raw mana + sand mana + light mana into crystal mana over time.',
    conversionRate: 0.25,
    difficultyFactor: 220,
    scalingFactor: 110,
    drainBase: 3,
    sourceManaTypes: ['raw', 'sand', 'light'],
    infiniteThreshold: 500,
  }),
  createAdvancedConversionDiscipline({
    id: 'regen-void',
    name: 'Void',
    manaType: 'void',
    cost: 18,
    description: 'Convert raw mana + dark mana + death mana into void mana over time.',
    conversionRate: 0.25,
    difficultyFactor: 220,
    scalingFactor: 110,
    drainBase: 3,
    sourceManaTypes: ['raw', 'dark', 'death'],
    infiniteThreshold: 500,
  }),

  // ── Exotic Elements (distance 3, rate 0.20/hr) ──────────────────────────
  createAdvancedConversionDiscipline({
    id: 'regen-stellar',
    name: 'Stellar',
    manaType: 'stellar',
    cost: 20,
    description: 'Convert raw mana + plasma mana + light mana into stellar mana over time.',
    conversionRate: 0.2,
    difficultyFactor: 240,
    scalingFactor: 120,
    drainBase: 3,
    sourceManaTypes: ['raw', 'plasma', 'light'],
    infiniteThreshold: 500,
  }),
  createAdvancedConversionDiscipline({
    id: 'regen-soul',
    name: 'Soul',
    manaType: 'soul',
    cost: 20,
    description: 'Convert raw mana + light mana + dark mana + transference mana into soul mana over time.',
    conversionRate: 0.2,
    difficultyFactor: 240,
    scalingFactor: 120,
    drainBase: 3,
    sourceManaTypes: ['raw', 'light', 'dark', 'transference'],
    infiniteThreshold: 550,
  }),
  createAdvancedConversionDiscipline({
    id: 'regen-plasma',
    name: 'Plasma',
    manaType: 'plasma',
    cost: 20,
    description: 'Convert raw mana + lightning mana + fire mana + transference mana into plasma mana over time.',
    conversionRate: 0.2,
    difficultyFactor: 240,
    scalingFactor: 120,
    drainBase: 3,
    sourceManaTypes: ['raw', 'lightning', 'fire', 'transference'],
    infiniteThreshold: 550,
  }),

  // ── Time (distance 4, rate 0.15/hr) ─────────────────────────────────────
  createAdvancedConversionDiscipline({
    id: 'regen-time',
    name: 'Time',
    manaType: 'time',
    cost: 22,
    description: 'Convert raw mana + soul mana + sand mana + transference mana into time mana over time.',
    conversionRate: 0.15,
    difficultyFactor: 260,
    scalingFactor: 130,
    drainBase: 3,
    sourceManaTypes: ['raw', 'soul', 'sand', 'transference'],
    infiniteThreshold: 600,
  }),
];
