import string
from collections import namedtuple
from random import random, choice, choices

from engine import colors


class StarSystem:
    def __init__(self, x, y, char, color):
        self.x = int(x)
        self.y = int(y)
        self.char = char
        self.color = color
        self.name = get_system_name(self)

    @property
    def position(self):
        return self.x, self.y

    @position.setter
    def position(self, pos):
        self.x = int(pos[0])
        self.y = int(pos[1])

def get_star_system(x, y, char, color):
    system = StarSystem(x, y, char, color)
    return system


StarTypeInfo = namedtuple(
    'StarTypeInfo',
    [
        'char',
        'color'
    ]
)

def get_system(x, y):
    return StarSystem(
        x,
        y,
        char='*' if random() < 0.2 else '.',
        color=choice([
            colors.red,
            colors.blue,
            colors.white,
            colors.yellow
        ])
    )

def get_system_name(star):
    r, g, b = star.color
    val = string.ascii_uppercase[(r + g + b) % 12]
    return val + '-' + ''.join(choices(string.ascii_uppercase + string.digits, k=10))