import logging
from dataclasses import dataclass
from typing import Union, List


@dataclass
class AppConfig:
    guiname: str
    name: str
    cmd: Union[List[str], str]
    path: str = "./apps/"
    persistent: bool = False
    white: bool = False

    def __post_init__(self):
        if not isinstance(self.cmd, list):
            self.cmd = [self.cmd]


# width
ScreenX = 80
# height
ScreenY = 40

DefaultBrightness = 0.6

Serial = "/dev/ttyTeensy"

# kills app after some seconds if it sends no data
NoDataTimeout = 40

LogLevel = logging.DEBUG

UseGui = False
GuiFPS = 20
GuiScaleFactor = 15

WebHost = "0.0.0.0"
WebPort = 8000

Apps = [
    # first app is always running as default
    AppConfig(guiname="Backlight", name="backlight", cmd="./backlight.py", white=True),

    AppConfig(guiname="Lines", name="lines", cmd="./lines.py"),
    AppConfig(guiname="Wolfram", name="wolfram", cmd="./wolfram.py"),
    AppConfig(guiname="Digi Clock", name="digiclock", cmd="./digi_clock.py"),
    AppConfig(guiname="Text Scroller MQTT", name="textscroll", cmd="./textscroll.py"),
    AppConfig(guiname="Spot", name="spot", cmd="./spot.py", white=True),
    AppConfig(guiname="Fireworks", name="fireworks", cmd="./fireworks.py", white=False),
    AppConfig(guiname="Flicker", name="flicker", cmd="./flicker"),

    AppConfig(guiname="Pixelflut", name="pixelflut", cmd="./pixelflut", persistent=True),
    # App(guiname="Pong", name="pong", cmd="pong.py"),
    AppConfig(guiname="YoutubeDL", name="youtubedl", cmd="./youtubedl.sh"),
    # App(guiname="Show Framebuffer", name="fbcp", cmd=["fbcp", "/dev/fb0"]),
    AppConfig(guiname="Strobo", name="strobo", cmd="./strobo.py"),
    # App(guiname="Beispiel", name="example", cmd="example.py"),
    # App(guiname="Beispiel2", name="example2", cmd="example2.py", white=True),
    AppConfig(guiname="Fibonacci Clock", name="fibonacci-clock", cmd="./fibonacci-clock.py"),
    AppConfig(guiname="Wget Video/Gif/Images", name="wget", cmd="./wget.sh"),

    # juergen/pixelfoo
    AppConfig(guiname="Congress noise", name="cnoise", cmd="./cnoise"),
    AppConfig(guiname="Color code", name="colorcode", cmd="./colorcode"),
    AppConfig(guiname="Game of Life", name="life", cmd="./life"),
    AppConfig(guiname="Matrix Code", name="matrix-code", cmd="./matrix-code"),
    AppConfig(guiname="Lorenz Attractor", name="lorenz", cmd="./lorenz"),
    AppConfig(guiname="Bitart", name="bitart", cmd="./bitart"),
    AppConfig(guiname="Thieles mønstre", name="thiele", cmd="./thiele"),
    AppConfig(guiname="Phase change", name="phase-change", cmd="./phase-change"),
    AppConfig(guiname="Phase change2", name="phase-change2", cmd="./phase-change2"),
    AppConfig(guiname="Primes", name="primes", cmd="./primes"),
    AppConfig(guiname="Alien Message", name="alien-message", cmd="./alien-message"),
    AppConfig(guiname="Dual Moodlight", name="bimood", cmd="./bimood"),
    AppConfig(guiname="Maze", name="maze", cmd="./maze"),
    AppConfig(guiname="Dual Maze", name="dualmaze", cmd="./dualmaze"),
    AppConfig(guiname="Predator & Prey", name="predprey", cmd="./predprey"),

    # App(guiname="Beat Saber Ceiling", name="beatsaberceiling", cmd="./beatsaberceiling.py", path="beatsaberceiling"),

    # mathpixel
    AppConfig(guiname="Structure formation", name="swifthohenberg", cmd="./swifthohenberg.py"),
    AppConfig(guiname="Quadratisch", name="quadratic", cmd="./quadratic.py"),
    AppConfig(guiname="Pendel", name="pendulum", cmd="./pendlum.py"),
    AppConfig(guiname="Konvergenz", name="convergence", cmd="./convergence.py"),
    AppConfig(guiname="Sinic", name="sinic", cmd="./sinic.py"),
    AppConfig(guiname="Sinic 2", name="sinic2", cmd="./sinic2.py"),

    # pixelthud
    AppConfig(guiname="Fading Pixels", name="fadingpxls", cmd="./fading_pixels.py"),
    AppConfig(guiname="Plane Wave", name="planewave", cmd="./plane_wave.py"),
    AppConfig(guiname="Rock-paper-scissors-spock-lizard", name="rps", cmd="./rps.py"),
    AppConfig(guiname="Doom Fire", name="doomfire", cmd="./doom_fire_psx2.py"),
    AppConfig(guiname="Shady", name="shady", cmd="./shady.sh"),
    # App(guiname="Maxwell FDTD", name="fdtd", cmd="./fdtd.py"),

    # App(guiname="Stream", name="stream", cmd="./stream.sh"),
    # App(guiname="Wget Video/Gif/Images", name="wget", cmd="./wget.sh"),
    # App(guiname="Tetris", name="tetris", cmd="./deckentetris/deckentetris.py"),
    # App(guiname="SkyScrapper", name="sky", cmd="./weather/main.py"),
    # App(guiname="Strobo", name="strobo", cmd="./strobo.py"),
    # App(guiname="Snake", name="snake", cmd="./snake.py"),
    # App(name="gif", cmd="./gif.sh"),
    # App(name="colormap", cmd="./colormap.py"),

    AppConfig(guiname="Pixel Canvas", name="pixelcanvas", cmd=""),
]
