from django.db import models
class Layer(models.Model):
    """Layers are basic containers with no metadata. Metadata for a layer
       will be managed by the catalog, primarily. The layer may store a
       cached bounding box for the features at some point. Each layer 
       can have multiple features (which can be in one or more layers)."""
    pass

class Schema(models.Model):
    layer = models.ForeignKey(Layer)
    key = models.CharField(max_length=255)
    datatype = models.CharField(max_length=255) # datattype/enum


class Feature(models.Model):
    """Features are a combination of properties and a geometry. The properties
       are associated by a foreign key to the properties. Features can be
       in multiple layers, identified by the manytomany field."""
    geometry = models.TextField()
    layers = models.ManyToManyField(Layer)

class LayerFeatureList(models.Model):
    """Used to store an ordered list of features for the layer"""
    feature = models.ForeignKey(Feature)
    layer = models.ForeignKey(Layer)
    order = models.IntegerField()

class Property(models.Model):
    """Properties are a key/value pair, associated with a feature."""
    key = models.CharField(max_length=255)
    value = models.TextField()
    feature = models.ForeignKey(Feature)
