# Path: DnD/modules/lib/helpers.py
# def sanitize_filename(name: str) -> str:
#     """Translates problematic characters in a filename into happier ones."""
#     return name.translate(str.maketrans(" '/:", "_@&$"))


import json
import re
from pathlib import Path
from bs4 import BeautifulSoup, Tag
from DnD.modules.lib.helpers import sanitize_filename
        'CR': elem.cr.text,
        # TODO: traits and actions?
    }


def parse_saves(text: str) -> list:
    saves = re.findall(r'(\w+)\s+([+-]?\d+)', text)
    mapper = {
        'Str': 'Strength',
        'Dex': 'Dexterity',
        'Con': 'Constitution',
        'Int': 'Intelligence',
        'Wis': 'Wisdom',
        'Cha': 'Charisma',
        'Strength': 'Strength',
        'Dexterity': 'Dexterity',
        'Constitution': 'Constitution',
        'Intelligence': 'Intelligence',
        'Wisdom': 'Wisdom',
        'Charisma': 'Charisma',
    }
    return [{mapper[save[0]]: int(save[1])} for save in saves]


def parse_skills(text: str) -> list:
    skills = re.findall(r'([\w\s]+?) ([+-]?\d+)', text)
    return [{skill[0]: int(skill[1])} for skill in skills]


def write_one(data: dict, outputdir: Path):

# Path: DnD/modules/lib/helpers.py
# def sanitize_filename(name: str) -> str:
#     """Translates problematic characters in a filename into happier ones."""
#     return name.translate(str.maketrans(" '/:", "_@&$"))


# Path: tools/scripts/read_monster_xml.py
import json
import re
from pathlib import Path
from bs4 import BeautifulSoup, Tag
from DnD.modules.lib.helpers import sanitize_filename

        'CR': elem.cr.text,
        # TODO: traits and actions?
    }


def parse_saves(text: str) -> list:
    saves = re.findall(r'(\w+)\s+([+-]?\d+)', text)
    mapper = {
        'Str': 'Strength',
        'Dex': 'Dexterity',
        'Con': 'Constitution',
        'Int': 'Intelligence',
        'Wis': 'Wisdom',
        'Cha': 'Charisma',
        'Strength': 'Strength',
        'Dexterity': 'Dexterity',
        'Constitution': 'Constitution',
        'Intelligence': 'Intelligence',
        'Wisdom': 'Wisdom',
        'Charisma': 'Charisma',
    }
    return [{mapper[save[0]]: int(save[1])} for save in saves]


def parse_skills(text: str) -> list:
    skills = re.findall(r'([\w\s]+?) ([+-]?\d+)', text)
    return [{skill[0]: int(skill[1])} for skill in skills]


def write_one(data: dict, outputdir: Path):

    file = outputdir / sanitize_filename(data['name'] + '.monster')