import { Equipment } from "./item.types";
import { DamageType, ExtendedStats, Stats } from "./stats.types";

// ====================================
// Animation Types
// ====================================
export interface AnimationConfig {
    key: string;
    frameStart: number;
    frameEnd: number;
    frameRate?: number;
    repeat: boolean;
}

export interface CharacterAnimations {
    idle?: AnimationConfig;
    attack?: AnimationConfig;
    combo?: AnimationConfig;
    special?: AnimationConfig;
    hurt?: AnimationConfig;
    death?: AnimationConfig;
    skill?: AnimationConfig;
    walk?: AnimationConfig;
    heal?: AnimationConfig;
}

// ====================================
// Role Types
// ====================================
export enum Role {
    TANK = 'tank',
    MELEE = 'melee',
    RANGED = 'ranged',
    HEALER = 'healer'
}

export interface TeamSlots {
    tank: number | null;
    melee: number | null;
    ranged: number | null;
    healer: number | null;
}

// ====================================
// Resource and Skill Types
// ====================================
export enum ResourcesType {
    NONE = 'none',
    MANA = 'mana',
    RAGE = 'rage',
    ENERGY = 'energy'
}

export enum SkillType {
    ATTACK = 'attack',
    COMBO = 'combo',
    SPECIAL = 'special',
    SKILL = 'skill',
    HEAL = 'heal',
    BUFF = 'buff',
    DEBUFF = 'debuff',
    DOT = 'dot',
    HOT = 'hot',
    ITEM = 'item'
}

export interface Skill {
    id: string;
    resourceType: ResourcesType;
    name: string;
    type: SkillType;
    damage?: number;
    healing?: number;
    cost: number;
    cooldown: number;
    currentCooldown: number;
    effects: string[];
    animationName?: string;
}

// ====================================
// Character Types
// ====================================
export interface CharacterCreateDto {
    name: string;
    stats: Stats;
    role: Role;
}

export interface CharacterUpdateDto {
    name?: string;
    level?: number;
    experience?: number;
    stats?: Partial<Stats>;
}

export interface CharacterDatabase {
    id?: number;
    name: string;
    role: Role;
    level?: number;
    experience?: number;
    stats: Stats;
    resources: ResourcesType;
    damageType: DamageType;
    equipments?: Equipment[];
    skills?: Skill[];
}

export interface CharacterInDungeon extends CharacterDatabase {
    stats: ExtendedStats;
    buffs: string[];
    debuffs: string[];
    inCombat: boolean;
    lastAction: number;
    targetId: string | null;
    isAlive: boolean;
}

export interface CharacterFrontend extends CharacterDatabase {
    animations: CharacterAnimations;
    position?: {
        x: number;
        y: number;
    };
}

// ====================================
// Character Defaults
// ====================================

export const CHARACTER_DEFAULTS: Record<string, CharacterFrontend> = {
    knight: {
        name: 'knight',
        damageType: DamageType.PHYSICAL_MELEE,
        role: Role.TANK,
        resources: ResourcesType.RAGE,
        stats: {
            strength: 5,
            agility: 2,
            intelligence: 0,
            vitality: 10,
            spirit: 3
        },
        animations: {
            idle: { key: 'idle', frameStart: 0, frameEnd: 5, frameRate: 8, repeat: true },
            walk: { key: 'walk', frameStart: 11, frameEnd: 18, frameRate: 12, repeat: true },
            attack: { key: 'attack', frameStart: 22, frameEnd: 29, frameRate: 12, repeat: false },
            combo: { key: 'combo', frameStart: 33, frameEnd: 42, frameRate: 12, repeat: false },
            special: { key: 'special', frameStart: 44, frameEnd: 54, frameRate: 12, repeat: false },
            skill: { key: 'skill', frameStart: 55, frameEnd: 58, frameRate: 12, repeat: false },
            hurt: { key: 'hurt', frameStart: 66, frameEnd: 69, frameRate: 12, repeat: false },
            death: { key: 'death', frameStart: 77, frameEnd: 80, frameRate: 10, repeat: false }
        },
        skills: [
            {
                id: '1',
                resourceType: ResourcesType.NONE,
                name: 'attack',
                type: SkillType.ATTACK,
                damage: 3,
                cost: 0,
                cooldown: 0,
                currentCooldown: 0,
                effects: [],
                animationName: 'attack'
            }
        ]
    },
    swordsman: {
        name: 'swordsman',
        damageType: DamageType.PHYSICAL_MELEE,
        role: Role.MELEE,
        resources: ResourcesType.RAGE,
        stats: {
            strength: 5,
            agility: 5,
            intelligence: 0,
            vitality: 8,
            spirit: 2
        },
        animations: {
            idle: { key: 'idle', frameStart: 0, frameEnd: 5, frameRate: 8, repeat: true },
            walk: { key: 'walk', frameStart: 15, frameEnd: 22, frameRate: 10, repeat: true },
            attack: { key: 'attack', frameStart: 30, frameEnd: 36, frameRate: 12, repeat: false },
            combo: { key: 'combo', frameStart: 45, frameEnd: 59, frameRate: 12, repeat: false },
            special: { key: 'special', frameStart: 60, frameEnd: 71, frameRate: 12, repeat: false },
            hurt: { key: 'hurt', frameStart: 75, frameEnd: 79, frameRate: 12, repeat: false },
            death: { key: 'death', frameStart: 90, frameEnd: 93, frameRate: 10, repeat: false }
        },
        skills: [
            {
                id: '1',
                resourceType: ResourcesType.NONE,
                name: 'attack',
                type: SkillType.ATTACK,
                damage: 4,
                cost: 0,
                cooldown: 0,
                currentCooldown: 0,
                effects: [],
                animationName: 'attack'
            },
            {
                id: '2',
                resourceType: ResourcesType.RAGE,
                name: 'combo',
                type: SkillType.COMBO,
                damage: 2,
                cost: 10,
                cooldown: 4,
                currentCooldown: 0,
                effects: [],
                animationName: 'combo'
            }
        ]
    },
    archer: {
        name: 'archer',
        damageType: DamageType.PHYSICAL_RANGED,
        role: Role.RANGED,
        resources: ResourcesType.ENERGY,
        stats: {
            strength: 4,
            agility: 10,
            intelligence: 0,
            vitality: 5,
            spirit: 1
        },
        animations: {
            idle: { key: 'idle', frameStart: 0, frameEnd: 5, frameRate: 8, repeat: true },
            walk: { key: 'walk', frameStart: 12, frameEnd: 19, frameRate: 10, repeat: true },
            attack: { key: 'attack', frameStart: 24, frameEnd: 32, frameRate: 12, repeat: false },
            combo: { key: 'combo', frameStart: 36, frameEnd: 47, frameRate: 12, repeat: false },
            hurt: { key: 'hurt', frameStart: 48, frameEnd: 51, frameRate: 12, repeat: false },
            death: { key: 'death', frameStart: 60, frameEnd: 63, frameRate: 10, repeat: false }
        },
        skills: [
            {
                id: '1',
                resourceType: ResourcesType.NONE,
                name: 'attack',
                type: SkillType.ATTACK,
                damage: 4,
                cost: 0,
                cooldown: 0,
                currentCooldown: 0,
                effects: [],
                animationName: 'attack'
            },
            {
                id: '2',
                resourceType: ResourcesType.ENERGY,
                name: 'combo',
                type: SkillType.COMBO,
                damage: 7,
                cost: 10,
                cooldown: 4,
                currentCooldown: 0,
                effects: [],
                animationName: 'combo'
            }
        ]
    },
    priest: {
        name: 'priest',
        damageType: DamageType.MAGICAL,
        role: Role.HEALER,
        resources: ResourcesType.MANA,
        stats: {
            strength: 0,
            agility: 0,
            intelligence: 6,
            vitality: 4,
            spirit: 10
        },
        animations: {
            idle: { key: 'idle', frameStart: 0, frameEnd: 5, frameRate: 8, repeat: true },
            walk: { key: 'walk', frameStart: 9, frameEnd: 16, frameRate: 10, repeat: true },
            attack: { key: 'attack', frameStart: 27, frameEnd: 35, frameRate: 10, repeat: false },
            heal: { key: 'heal', frameStart: 54, frameEnd: 59, frameRate: 12, repeat: false },
            hurt: { key: 'hurt', frameStart: 72, frameEnd: 75, frameRate: 12, repeat: false },
            death: { key: 'death', frameStart: 81, frameEnd: 84, frameRate: 10, repeat: false }
        },
        skills: [
            {
                id: '1',
                resourceType: ResourcesType.NONE,
                name: 'attack',
                type: SkillType.ATTACK,
                damage: 2,
                cost: 0,
                cooldown: 0,
                currentCooldown: 0,
                effects: [],
                animationName: 'attack'
            },
            {
                id: '2',
                resourceType: ResourcesType.MANA,
                name: 'heal',
                type: SkillType.HEAL,
                healing: 5,
                cost: 10,
                cooldown: 4,
                currentCooldown: 0,
                effects: [],
                animationName: 'heal'
            }
        ]
    },
    skeleton: {
        name: 'skeleton',
        damageType: DamageType.PHYSICAL_MELEE,
        role: Role.MELEE,
        resources: ResourcesType.RAGE,
        stats: {
            strength: 2,
            agility: 1,
            intelligence: 0,
            vitality: 3,
            spirit: 0
        },
        animations: {
            idle: { key: 'idle', frameStart: 0, frameEnd: 5, frameRate: 8, repeat: true },
            walk: { key: 'walk', frameStart: 8, frameEnd: 15, frameRate: 10, repeat: true },
            attack: { key: 'attack', frameStart: 16, frameEnd: 21, frameRate: 12, repeat: false },
            combo: { key: 'combo', frameStart: 24, frameEnd: 30, frameRate: 12, repeat: false },
            special: { key: 'special', frameStart: 32, frameEnd: 35, frameRate: 12, repeat: false },
            hurt: { key: 'hurt', frameStart: 40, frameEnd: 43, frameRate: 12, repeat: false },
            death: { key: 'death', frameStart: 48, frameEnd: 51, frameRate: 10, repeat: false }
        },
        skills: [
            {
                id: '1',
                resourceType: ResourcesType.NONE,
                name: 'attack',
                type: SkillType.ATTACK,
                damage: 2,
                cost: 0,
                cooldown: 0,
                currentCooldown: 0,
                effects: [],
                animationName: 'attack'
            },
            {
                id: '2',
                resourceType: ResourcesType.RAGE,
                name: 'combo',
                type: SkillType.COMBO,
                damage: 2,
                cost: 10,
                cooldown: 4,
                currentCooldown: 0,
                effects: [],
                animationName: 'combo'
            }
        ]
    },
    skeleton_archer: {
        name: 'skeleton_archer',
        damageType: DamageType.PHYSICAL_RANGED,
        role: Role.RANGED,
        resources: ResourcesType.ENERGY,
        stats: {
            strength: 2,
            agility: 1,
            intelligence: 0,
            vitality: 2,
            spirit: 0
        },
        animations: {
            idle: { key: 'idle', frameStart: 0, frameEnd: 5, frameRate: 8, repeat: true },
            walk: { key: 'walk', frameStart: 9, frameEnd: 16, frameRate: 10, repeat: true },
            attack: { key: 'attack', frameStart: 18, frameEnd: 26, frameRate: 12, repeat: false },
            hurt: { key: 'hurt', frameStart: 27, frameEnd: 30, frameRate: 12, repeat: false },
            death: { key: 'death', frameStart: 36, frameEnd: 39, frameRate: 10, repeat: false }
        },
        skills: [
            {
                id: '1',
                resourceType: ResourcesType.NONE,
                name: 'attack',
                type: SkillType.ATTACK,
                damage: 2,
                cost: 0,
                cooldown: 0,
                currentCooldown: 0,
                effects: [],
                animationName: 'attack'
            }
        ]
    },
    armored_skeleton: {
        name: 'armored_skeleton',
        damageType: DamageType.PHYSICAL_MELEE,
        role: Role.MELEE,
        resources: ResourcesType.RAGE,
        stats: {
            strength: 3,
            agility: 1,
            intelligence: 0,
            vitality: 4,
            spirit: 0
        },
        animations: {
            idle: { key: 'idle', frameStart: 0, frameEnd: 5, frameRate: 8, repeat: true },
            walk: { key: 'walk', frameStart: 9, frameEnd: 16, frameRate: 10, repeat: true },
            attack: { key: 'attack', frameStart: 18, frameEnd: 25, frameRate: 12, repeat: false },
            combo: { key: 'combo', frameStart: 27, frameEnd: 35, frameRate: 12, repeat: false },
            hurt: { key: 'hurt', frameStart: 36, frameEnd: 49, frameRate: 12, repeat: false },
            death: { key: 'death', frameStart: 45, frameEnd: 48, frameRate: 10, repeat: false }
        },
        skills: [
            {
                id: '1',
                resourceType: ResourcesType.NONE,
                name: 'attack',
                type: SkillType.ATTACK,
                damage: 3,
                cost: 0,
                cooldown: 0,
                currentCooldown: 0,
                effects: [],
                animationName: 'attack'
            },
            {
                id: '2',
                resourceType: ResourcesType.RAGE,
                name: 'combo',
                type: SkillType.COMBO,
                damage: 2,
                cost: 10,
                cooldown: 4,
                currentCooldown: 0,
                effects: [],
                animationName: 'combo'
            }
        ]
    }
}; 
