# Path: farmsList/public/models.py
# class Parcel(SurrogatePK, Model):
#     __tablename__ = 'parcels'
#     size = Column(db.Numeric(precision=6, scale=2), nullable = False)
#     water = Column(db.Numeric(precision=3, scale=0), nullable=True)
#     soil = Column(db.String(400), nullable=True)
#     zoning = Column(db.String(80), nullable=False)
#     geometry = Column(db.String(6250000), nullable=False)
#     center = Column(db.String(2000), nullable=False)
#     geom = Column(Geometry(geometry_type='MULTIPOLYGON'))
#     cent = Column(Geometry(geometry_type='POINT'))
#     developmentPlan = Column(db.String(400), nullable=True)
#     restrictions = Column(db.String(400), nullable=True)
#     address = Column(db.String(400), nullable=True)
#     apn = Column(db.BigInteger(), nullable=False, unique=True)
#     jurisdiction = Column(db.String(400))
#     landType = Column(db.String(80), nullable=True)
#     landUse = Column(db.String(80), nullable=True)
# 
#     def __init__(self, **kwargs):
#         db.Model.__init__(self, **kwargs)
# 
#     def __repr__(self):
#         return '<Parcel({id})>'.format(id=self.id)
# 
# class Farmland(SurrogatePK, Model):
#     __tablename__ = 'farmlands'
#     size = Column(db.Numeric(precision=6, scale=2), nullable = False)
#     hasWater = Column(db.Boolean(), nullable=False, server_default='False')
#     water = Column(db.Numeric(precision=3, scale=0), nullable=True)
#     public = Column(db.Boolean(), nullable=False, server_default='False')
#     soil = Column(db.String(400), nullable=True)
#     zoning = Column(db.String(80), nullable=False)
#     geometry = Column(Geometry(geometry_type='MULTIPOLYGON'), nullable=False)
#     center = Column(Geometry(geometry_type='POINT'), nullable=False)
#     developmentPlan = Column(db.String(400), nullable=True)
#     ownerName = Column(db.String(400), nullable=True)
#     address = Column(db.String(400), nullable=True)
#     email = Column(db.String(80), nullable=True)
#     monthlyCost = Column(db.Numeric(precision=7, scale=2), nullable = False)
#     priorUses = Column(db.String(10000), nullable=True)
# 
#     def __init__(self, **kwargs):
#         db.Model.__init__(self, **kwargs)
# 
#     def __repr__(self):
#         return '<Farmland({id})>'.format(id=self.id)
# 
# class AdditionalLayer(SurrogatePK, Model):
#     __tablename__ = 'additional_layers'
#     name = Column(db.String(400), nullable=False)
#     geom = Column(Geometry(geometry_type='MULTIPOLYGON'), nullable=False)
# 
#     def __init__(self, **kwargs):
#         db.Model.__init__(self, **kwargs)
# 
#     def __repr__(self):
#         return '<AdditionalLayer({id}, {name})>'.format(id=self.id, name=self.name)
# 
# Path: farmsList/database.py
# class CRUDMixin(object):
# class Model(CRUDMixin, db.Model):
# class SurrogatePK(object):
#     def create(cls, **kwargs):
#     def update(self, commit=True, **kwargs):
#     def save(self, commit=True):
#     def delete(self, commit=True):
#     def get_by_id(cls, id):
# def ReferenceCol(tablename, nullable=False, pk_name='id', **kwargs):


import json
import jsonpickle
from decimal import Decimal
from flask import Blueprint
from farmsList.public.models import Parcel, Farmland, AdditionalLayer
from farmsList.database import db
from sqlalchemy import func



blueprint = Blueprint('api', __name__, url_prefix='/api',
						static_folder="../static")

def pre_json_encode(obj):
	for key in obj.__dict__.keys():
		if isinstance(obj.__dict__[key], Decimal):
			obj.__dict__[key] = float(obj.__dict__[key])
	obj.__dict__['_sa_instance_state'] = None
	return obj

@blueprint.route("/parcel/", methods=["GET", "POST"])
def api_parcel():

# Path: farmsList/public/models.py
# class Parcel(SurrogatePK, Model):
#     __tablename__ = 'parcels'
#     size = Column(db.Numeric(precision=6, scale=2), nullable = False)
#     water = Column(db.Numeric(precision=3, scale=0), nullable=True)
#     soil = Column(db.String(400), nullable=True)
#     zoning = Column(db.String(80), nullable=False)
#     geometry = Column(db.String(6250000), nullable=False)
#     center = Column(db.String(2000), nullable=False)
#     geom = Column(Geometry(geometry_type='MULTIPOLYGON'))
#     cent = Column(Geometry(geometry_type='POINT'))
#     developmentPlan = Column(db.String(400), nullable=True)
#     restrictions = Column(db.String(400), nullable=True)
#     address = Column(db.String(400), nullable=True)
#     apn = Column(db.BigInteger(), nullable=False, unique=True)
#     jurisdiction = Column(db.String(400))
#     landType = Column(db.String(80), nullable=True)
#     landUse = Column(db.String(80), nullable=True)
# 
#     def __init__(self, **kwargs):
#         db.Model.__init__(self, **kwargs)
# 
#     def __repr__(self):
#         return '<Parcel({id})>'.format(id=self.id)
# 
# class Farmland(SurrogatePK, Model):
#     __tablename__ = 'farmlands'
#     size = Column(db.Numeric(precision=6, scale=2), nullable = False)
#     hasWater = Column(db.Boolean(), nullable=False, server_default='False')
#     water = Column(db.Numeric(precision=3, scale=0), nullable=True)
#     public = Column(db.Boolean(), nullable=False, server_default='False')
#     soil = Column(db.String(400), nullable=True)
#     zoning = Column(db.String(80), nullable=False)
#     geometry = Column(Geometry(geometry_type='MULTIPOLYGON'), nullable=False)
#     center = Column(Geometry(geometry_type='POINT'), nullable=False)
#     developmentPlan = Column(db.String(400), nullable=True)
#     ownerName = Column(db.String(400), nullable=True)
#     address = Column(db.String(400), nullable=True)
#     email = Column(db.String(80), nullable=True)
#     monthlyCost = Column(db.Numeric(precision=7, scale=2), nullable = False)
#     priorUses = Column(db.String(10000), nullable=True)
# 
#     def __init__(self, **kwargs):
#         db.Model.__init__(self, **kwargs)
# 
#     def __repr__(self):
#         return '<Farmland({id})>'.format(id=self.id)
# 
# class AdditionalLayer(SurrogatePK, Model):
#     __tablename__ = 'additional_layers'
#     name = Column(db.String(400), nullable=False)
#     geom = Column(Geometry(geometry_type='MULTIPOLYGON'), nullable=False)
# 
#     def __init__(self, **kwargs):
#         db.Model.__init__(self, **kwargs)
# 
#     def __repr__(self):
#         return '<AdditionalLayer({id}, {name})>'.format(id=self.id, name=self.name)
# 
# Path: farmsList/database.py
# class CRUDMixin(object):
# class Model(CRUDMixin, db.Model):
# class SurrogatePK(object):
#     def create(cls, **kwargs):
#     def update(self, commit=True, **kwargs):
#     def save(self, commit=True):
#     def delete(self, commit=True):
#     def get_by_id(cls, id):
# def ReferenceCol(tablename, nullable=False, pk_name='id', **kwargs):


# Path: farmsList/public/api.py
import json
import jsonpickle
from decimal import Decimal
from flask import Blueprint
from farmsList.public.models import Parcel, Farmland, AdditionalLayer
from farmsList.database import db
from sqlalchemy import func




blueprint = Blueprint('api', __name__, url_prefix='/api',
						static_folder="../static")

def pre_json_encode(obj):
	for key in obj.__dict__.keys():
		if isinstance(obj.__dict__[key], Decimal):
			obj.__dict__[key] = float(obj.__dict__[key])
	obj.__dict__['_sa_instance_state'] = None
	return obj

@blueprint.route("/parcel/", methods=["GET", "POST"])
def api_parcel():

	farmlandData = Farmland.query.filter(Farmland.public == True).all()