import logging

from moo import bootstrap
from moo.core import code, create, lookup
from moo.core.models import Player, User

log = logging.getLogger(__name__)

repo = bootstrap.initialize_dataset("test")
wizard = lookup("Wizard")
user = User.objects.create(username="wizard")
Player.objects.create(user=user, avatar=wizard, wizard=True)
containers = lookup("container class")

with code.ContextManager(wizard, log.info):
    bag = create("bag of holding", parents=[containers], location=wizard)
    hammer = create("wizard hammer", location=bag)
    book = create("class book", parents=[containers], location=bag)
    players = create("player class", location=book)
    guests = create("guest class", location=book)
    guests.parents.add(players)
    authors = create("author class", location=book)
    authors.parents.add(players)
    programmers = create("programmer class", location=book)
    programmers.parents.add(authors)
    wizards = create("wizard class", location=book)
    wizards.parents.add(programmers)

    wizard.parents.add(wizards)

    rooms = create("room class", parents=[containers], location=book)
    rooms.set_property("description", "There's not much to see here.")

    lab = create("The Laboratory")
    lab.parents.add(rooms)
    lab.set_property(
        "description",
        """A cavernous laboratory filled with gadgetry of every kind,
    this seems like a dumping ground for every piece of dusty forgotten
    equipment a mad scientist might require.""",
    )

    wizard.location = lab
    wizard.save()

    new_player = create(name="Player", unique_name=True, location=lab)
    p = Player.objects.create()
    p.avatar = new_player
    p.save()

    new_player.parents.add(players, containers)
    new_player.owner = new_player
    new_player.save()

    bootstrap.load_verbs(repo, "moo.bootstrap.test_verbs")
