from sys import stderr, stdout
from enum import Enum
from colored import fg, attr

PANTAM: str = fg("yellow") + attr("bold") + "PANTAM" + attr("reset")

colour_msg = lambda msg, colour: fg(colour) + attr("bold") + msg + attr("reset")
info_msg = lambda msg: colour_msg(msg, "blue")
success_msg = lambda msg: colour_msg(msg, "green")
error_msg = lambda msg: colour_msg(msg, "red")


class NewLine(Enum):
    before = 1
    after = 2
    both = 3


def write_msg(msg: str, spacing: NewLine = None) -> None:
    """Write message to stdout"""
    prefix: str = "\n" if spacing in (NewLine.before, NewLine.both) else ""
    suffix: str = "\n" if spacing in (NewLine.after, NewLine.both) else ""
    stdout.write("%s%s%s" % (prefix, msg, suffix))


def write_error(msg: str) -> None:
    """Write message to stderr"""
    stderr.write("\n%s\n" % msg)


welcome_msg = (
    lambda: PANTAM
    + """

The microframework for microservices.

Let's build your app...

"""
)

name_index_file_msg = lambda: "What is the name of your main script?"

name_actions_folder_msg = lambda: "What is the name of your actions folder?"


def create_actions_file_msg(second_run: bool):
    """Actions File Message"""
    article = "another" if second_run else "an"
    return "Do you want to create %s action file?" % article


name_actions_file_msg = lambda: "What is the name of your actions file?"

confirm_structure_msg = (
    lambda structure: """Your application will look like this:
%s

Happy to proceed?"""
    % structure
)

[((5, 55, 5, 68), 'colored.attr', 'attr', ({(5, 60, 5, 67): '"""reset"""'}, {}), "('reset')", False, 'from colored import fg, attr\n'), ((23, 4, 23, 50), 'sys.stdout.write', 'stdout.write', ({(23, 17, 23, 49): "('%s%s%s' % (prefix, msg, suffix))"}, {}), "('%s%s%s' % (prefix, msg, suffix))", False, 'from sys import stderr, stdout\n'), ((28, 4, 28, 32), 'sys.stderr.write', 'stderr.write', ({(28, 17, 28, 31): "('\\n%s\\n' % msg)"}, {}), "('\\n%s\\n' % msg)", False, 'from sys import stderr, stdout\n'), ((7, 67, 7, 80), 'colored.attr', 'attr', ({(7, 72, 7, 79): '"""reset"""'}, {}), "('reset')", False, 'from colored import fg, attr\n'), ((5, 14, 5, 26), 'colored.fg', 'fg', ({(5, 17, 5, 25): '"""yellow"""'}, {}), "('yellow')", False, 'from colored import fg, attr\n'), ((5, 29, 5, 41), 'colored.attr', 'attr', ({(5, 34, 5, 40): '"""bold"""'}, {}), "('bold')", False, 'from colored import fg, attr\n'), ((7, 33, 7, 43), 'colored.fg', 'fg', ({(7, 36, 7, 42): 'colour'}, {}), '(colour)', False, 'from colored import fg, attr\n'), ((7, 46, 7, 58), 'colored.attr', 'attr', ({(7, 51, 7, 57): '"""bold"""'}, {}), "('bold')", False, 'from colored import fg, attr\n')]