import discord
from minecraft_manager.models import Application, Player


def build_info(application):
    embed = discord.Embed(colour=discord.Colour(0x417505))
    embed.set_thumbnail(
        url="https://minotar.net/helm/{0}/100.png".format(application.username))
    embed.add_field(name="Application ID", value=application.id)
    embed.add_field(name="Username", value=application.username.replace("_", "\\_"))
    embed.add_field(name="Age", value=application.age)
    embed.add_field(name="Type of Player", value=application.player_type)
    embed.add_field(name="Ever been banned", value=application.ever_banned)
    if application.ever_banned:
        embed.add_field(name="Reason for being banned", value=application.ever_banned_explanation)
    embed.add_field(name="Reference", value=application.reference)
    embed.add_field(name="Read the Rules", value=application.read_rules)
    embed.add_field(name="Date", value=application.date_display)
    embed.add_field(name="Status", value=application.status)
    return embed


def get_application(app_id):
    try:
        return Application.objects.get(id=app_id)
    except:
        return None