# Path: wham/fields.py
# class WhamCharField(WhamFieldMixin, models.TextField):
# 
#     @property
#     def type_repr(self):
#         return 'char'
# 
# class WhamTextField(WhamFieldMixin, models.TextField):
# 
#     @property
#     def type_repr(self):
#         return 'text'
# 
# class WhamIntegerField(WhamFieldMixin, models.IntegerField):
# 
#     @property
#     def type_repr(self):
#         return 'integer'
# 
# class WhamManyToManyField(models.ManyToManyField):
# 
#     def __init__(self, *args, **kwargs):
#         self.wham_result_path = kwargs.pop('wham_result_path', None)
#         self.wham_endpoint = kwargs.pop('wham_endpoint', None)
#         self.wham_results_path = kwargs.pop('wham_results_path', ())
#         self.wham_pk_param = kwargs.pop('wham_pk_param', None)
#         self.wham_params = kwargs.pop('wham_params', {})
#         return super(WhamManyToManyField, self).__init__(*args, **kwargs)
# 
# 
# 
# 
#     @property
#     def type_repr(self):
#         return 'many to many'
# 
# class WhamFloatField(WhamFieldMixin, models.FloatField):
# 
#     @property
#     def type_repr(self):
#         return 'float'
# 
# class WhamForeignKey(models.ForeignKey):
# 
#     def __init__(self, *args, **kwargs):
#         self.wham_result_path = kwargs.pop('wham_result_path', None)
#         self.wham_endpoint = kwargs.pop('wham_endpoint', None)
#         self.wham_results_path = kwargs.pop('wham_results_path', ())
#         self.wham_pk_param = kwargs.pop('wham_pk_param', None)
#         self.wham_params = kwargs.pop('wham_params', {})
#         return super(WhamForeignKey, self).__init__(*args, **kwargs)
# 
#     def get_result_path(self):
#         result_path = self.wham_result_path
#         if not result_path:
#             return (self.name,)
#         else:
#             return result_path
# 
#     @property
#     def type_repr(self):
#         return 'foreign key'
# 
# Path: wham/models.py
# class WhamModel(models.Model):
# 
#     objects = WhamManager()
# 
#     class Meta():
#         abstract = True


from django.db import models
from wham.fields import WhamCharField, WhamTextField, WhamIntegerField, \
    WhamManyToManyField, WhamFloatField, WhamForeignKey
from wham.models import WhamModel


class EventbriteVenue(WhamModel):

    id = WhamCharField(max_length=255, primary_key=True)
    name = WhamTextField()
    latitude = WhamFloatField()
    longitude = WhamFloatField()

    city = WhamTextField(wham_result_path=('address', 'city'), null=True)
    country = WhamTextField(wham_result_path=('address', 'country'), null=True)
    region = WhamTextField(wham_result_path=('address', 'region'), null=True)
    address_1 = WhamTextField(wham_result_path=('address', 'address_1'), null=True)
    address_2 = WhamTextField(wham_result_path=('address', 'address_2'), null=True)
    country_name = WhamTextField(wham_result_path=('address', 'country_name'), null=True)

    class Meta:
        db_table = 'eventbrite_venue'

    def __unicode__(self):
        return self.name


class EventbriteEvent(WhamModel):

    id = WhamCharField(max_length=255, primary_key=True)
    name = WhamTextField(wham_result_path=('name', 'text'))
    resource_uri = WhamTextField()
    url = WhamTextField()
    capacity = WhamIntegerField()

# Path: wham/fields.py
# class WhamCharField(WhamFieldMixin, models.TextField):
# 
#     @property
#     def type_repr(self):
#         return 'char'
# 
# class WhamTextField(WhamFieldMixin, models.TextField):
# 
#     @property
#     def type_repr(self):
#         return 'text'
# 
# class WhamIntegerField(WhamFieldMixin, models.IntegerField):
# 
#     @property
#     def type_repr(self):
#         return 'integer'
# 
# class WhamManyToManyField(models.ManyToManyField):
# 
#     def __init__(self, *args, **kwargs):
#         self.wham_result_path = kwargs.pop('wham_result_path', None)
#         self.wham_endpoint = kwargs.pop('wham_endpoint', None)
#         self.wham_results_path = kwargs.pop('wham_results_path', ())
#         self.wham_pk_param = kwargs.pop('wham_pk_param', None)
#         self.wham_params = kwargs.pop('wham_params', {})
#         return super(WhamManyToManyField, self).__init__(*args, **kwargs)
# 
# 
# 
# 
#     @property
#     def type_repr(self):
#         return 'many to many'
# 
# class WhamFloatField(WhamFieldMixin, models.FloatField):
# 
#     @property
#     def type_repr(self):
#         return 'float'
# 
# class WhamForeignKey(models.ForeignKey):
# 
#     def __init__(self, *args, **kwargs):
#         self.wham_result_path = kwargs.pop('wham_result_path', None)
#         self.wham_endpoint = kwargs.pop('wham_endpoint', None)
#         self.wham_results_path = kwargs.pop('wham_results_path', ())
#         self.wham_pk_param = kwargs.pop('wham_pk_param', None)
#         self.wham_params = kwargs.pop('wham_params', {})
#         return super(WhamForeignKey, self).__init__(*args, **kwargs)
# 
#     def get_result_path(self):
#         result_path = self.wham_result_path
#         if not result_path:
#             return (self.name,)
#         else:
#             return result_path
# 
#     @property
#     def type_repr(self):
#         return 'foreign key'
# 
# Path: wham/models.py
# class WhamModel(models.Model):
# 
#     objects = WhamManager()
# 
#     class Meta():
#         abstract = True


# Path: wham/apis/eventbrite/models.py
from django.db import models
from wham.fields import WhamCharField, WhamTextField, WhamIntegerField, \
    WhamManyToManyField, WhamFloatField, WhamForeignKey
from wham.models import WhamModel



class EventbriteVenue(WhamModel):

    id = WhamCharField(max_length=255, primary_key=True)
    name = WhamTextField()
    latitude = WhamFloatField()
    longitude = WhamFloatField()

    city = WhamTextField(wham_result_path=('address', 'city'), null=True)
    country = WhamTextField(wham_result_path=('address', 'country'), null=True)
    region = WhamTextField(wham_result_path=('address', 'region'), null=True)
    address_1 = WhamTextField(wham_result_path=('address', 'address_1'), null=True)
    address_2 = WhamTextField(wham_result_path=('address', 'address_2'), null=True)
    country_name = WhamTextField(wham_result_path=('address', 'country_name'), null=True)

    class Meta:
        db_table = 'eventbrite_venue'

    def __unicode__(self):
        return self.name


class EventbriteEvent(WhamModel):

    id = WhamCharField(max_length=255, primary_key=True)
    name = WhamTextField(wham_result_path=('name', 'text'))
    resource_uri = WhamTextField()
    url = WhamTextField()
    capacity = WhamIntegerField()

    venue = WhamForeignKey(EventbriteVenue, null=True) #this should be a foreign key! But we only support m2m so far.