# Path: embedmaker/serialize.py
# def serialize_embed(embed: discord.Embed) -> dict:
# def deserialize_embed(conf: dict) -> discord.Embed:


import re
import discord
import yaml
import yaml.reader
from redbot.core import commands
from .serialize import deserialize_embed, template
from .time_utils import parse_time

    return ts


# TODO: Pull the logic out of d.py converter to not do this here...
async def handle_color(ctx, to_set) -> int:
    x: int
    try:
        conv = discord.ext.commands.ColourConverter()
        x = (await conv.convert(ctx, to_set)).value
    except Exception:
        if isinstance(to_set, str) and to_set.startswith("#"):
            x = int(to_set.lstrip("#"), 16)
        else:
            x = int(to_set)

    return x


# TODO : Use schema here. Will allow giving back reasonable error messages on failures.
async def embed_from_userstr(ctx: commands.Context, string: str) -> discord.Embed:
    ret: dict = {"initable": {}, "settable": {}, "fields": []}
    string = string_preprocessor(string)

    parsed = yaml.safe_load(string)
    ret["fields"] = [
        field_data for _index, field_data in sorted(parsed.get("fields", {}).items())
    ]

    for outer_key in ["initable", "settable"]:

# Path: embedmaker/serialize.py
# def serialize_embed(embed: discord.Embed) -> dict:
# def deserialize_embed(conf: dict) -> discord.Embed:


# Path: embedmaker/yaml_parse.py
import re
import discord
import yaml
import yaml.reader
from redbot.core import commands
from .serialize import deserialize_embed, template
from .time_utils import parse_time


    return ts


# TODO: Pull the logic out of d.py converter to not do this here...
async def handle_color(ctx, to_set) -> int:
    x: int
    try:
        conv = discord.ext.commands.ColourConverter()
        x = (await conv.convert(ctx, to_set)).value
    except Exception:
        if isinstance(to_set, str) and to_set.startswith("#"):
            x = int(to_set.lstrip("#"), 16)
        else:
            x = int(to_set)

    return x


# TODO : Use schema here. Will allow giving back reasonable error messages on failures.
async def embed_from_userstr(ctx: commands.Context, string: str) -> discord.Embed:
    ret: dict = {"initable": {}, "settable": {}, "fields": []}
    string = string_preprocessor(string)

    parsed = yaml.safe_load(string)
    ret["fields"] = [
        field_data for _index, field_data in sorted(parsed.get("fields", {}).items())
    ]

    for outer_key in ["initable", "settable"]:

        for inner_key in template[outer_key].keys():