from sqlobject import *
import time, datetime

class WildCoord(SQLObject):
  # TODO: make a single sqlType="Point" column for x and y for better
  # integration with pgSQL's spatial extensions

  coords     = Col(sqlType="POINT", default="(0,0)")
  name       = StringCol(length=20, default="{DIn the Tempest{n")
  longdesc   = StringCol(default="{gYou are in the Tempest.{n")
  decay      = BoolCol(default=True)
  monstergen = BoolCol(default=True)
  monsterct  = Col(sqlType="SMALLINT", default=0)
  monstermax = Col(sqlType="SMALLINT", default=1)
  accessed   = DateTimeCol(default=DateTimeCol.now)
  
  chars     = MultipleJoin('Person', joinColumn='wild_coords_id')

class Account(SQLObject):
  name       = StringCol(length=20)
  password   = StringCol(length=20, default=None)

  characters = MultipleJoin('Person', joinColumn='owner_id')

class Person(SQLObject):
  connected   = BoolCol(default=True)
  uid         = IntCol(default=9999)   # doesn't matter for mobs, and hopefully won't for chars
  owner       = ForeignKey('Account')
  name        = StringCol(length=20)
  race        = EnumCol(enumValues=['wraith', 'human'], default='wraith')
  sex         = EnumCol(enumValues=['male', 'female', 'neutral'], default='neutral')
  size        = Col(sqlType = "SMALLINT", default=2)
  roomDesc    = StringCol(length=100, default=name)
  longDesc    = StringCol(default=None)
  inventory   = PickleCol(default=None)
  lineOfSight = Col(sqlType = "CIRCLE", default=None)
  visibility  = Col(sqlType = "CIRCLE", default=None)
  wildCoords  = ForeignKey('WildCoord')

try:
  connection_string = "postgres://harrowing:harrowing@localhost/harrowingdb?debug=1debugOutput=1"
  connection = connectionForURI(connection_string)
  sqlhub.processConnection = connection

except:
  print "Cannot connect to SQL server."
