# -*- coding: utf-8 -*-

from application.app import db, ma
from .base import PrimaryModel 
from marshmallow import Schema, fields, INCLUDE, EXCLUDE

class AreaModel(PrimaryModel):
    __tablename__ = 'evm_area'

<<<<<<< HEAD
    areaCode = db.Column(db.String(20), index = True)
    areaName = db.Column(db.String(20), index = True)
    level = db.Column(db.Integer, default = 1)
    cityCode = db.Column(db.Integer)
    center = db.Column(db.String(20), index = True)
    parentId = db.Column(db.String(20))
    hasChildren = db.Column(db.Boolean)
=======
    areaCode = db.Column(db.String(20), index = True, nullable = False)
    areaName = db.Column(db.String(20), index = True, nullable = False)
    level = db.Column(db.Integer, nullable = False, default = 1)
    cityCode = db.Column(db.Integer, nullable = True)
    center = db.Column(db.String(20), index = True, nullable = False)
    parentId = db.Column(db.String(20), nullable = True)
    hasChildren = db.Column(db.Boolean, nullable = True)
>>>>>>> 735d39eb4d0c3134b62bf4fe1b7a2ca0ea8da1ca

    # __table_args__ = (
    #     db.Index('idx_xxx', 'xxx', mysql_using='btree'),
    # )

    def __init__(self, areaCode, areaName, level, cityCode, center, parentId, hasChildren):
        self.areaCode = areaCode
        self.areaName = areaName
        self.level = level
        self.cityCode = cityCode
        self.center = center
        self.parentId = parentId
        self.hasChildren = hasChildren

    def __repr__(self):
        return '<AreaModel %r>' % (self.areaCode)

    def to_json(self):
        return {
            'areaCode': self.areaCode,
            'areaName': self.areaName,
            'level': self.level,
            'cityCode': self.cityCode,
            'center': self.center,
            'parentId': self.parentId,
            'hasChildren': self.hasChildren,
        }


class PostAreaSchema(ma.SQLAlchemySchema):
    class Meta:
        # unknown = INCLUDE # 未知字段默认包含
<<<<<<< HEAD
        # unknown = EXCLUDE # 未知字段默认排除
=======
        unknown = EXCLUDE # 未知字段默认排除
>>>>>>> 735d39eb4d0c3134b62bf4fe1b7a2ca0ea8da1ca
        model = AreaModel

    areaCode = ma.auto_field()
    areaName = ma.auto_field()
    level = ma.auto_field()
<<<<<<< HEAD
=======
    parentId = ma.auto_field()
    hasChildren = ma.auto_field()
>>>>>>> 735d39eb4d0c3134b62bf4fe1b7a2ca0ea8da1ca
    cityCode = ma.auto_field()
    center = ma.auto_field()

postAreaSchema = PostAreaSchema()
<<<<<<< HEAD
postAreasSchema = PostAreaSchema(many=True)
=======
>>>>>>> 735d39eb4d0c3134b62bf4fe1b7a2ca0ea8da1ca

class DeleteAreaSchema(ma.SQLAlchemySchema):
    class Meta:
        # unknown = INCLUDE # 未知字段默认包含
<<<<<<< HEAD
        # unknown = EXCLUDE # 未知字段默认排除
=======
        unknown = EXCLUDE # 未知字段默认排除
>>>>>>> 735d39eb4d0c3134b62bf4fe1b7a2ca0ea8da1ca
        model = AreaModel


deleteAreaSchema = DeleteAreaSchema()

class GetListAreaSchema(ma.SQLAlchemySchema):
    class Meta:
        # unknown = INCLUDE # 未知字段默认包含
<<<<<<< HEAD
        # unknown = EXCLUDE # 未知字段默认排除
=======
        unknown = EXCLUDE # 未知字段默认排除
>>>>>>> 735d39eb4d0c3134b62bf4fe1b7a2ca0ea8da1ca
        model = AreaModel

    page = fields.Integer(required=False)
    pageSize = fields.Integer(required=False)
    areaName = ma.auto_field()
    level = ma.auto_field()
    parentId = ma.auto_field()
    hasChildren = ma.auto_field()
    field = fields.String(required=False, length=None)

getListAreaSchema = GetListAreaSchema()
<<<<<<< HEAD
=======
getListAreasSchema = GetListAreaSchema(many=True)
>>>>>>> 735d39eb4d0c3134b62bf4fe1b7a2ca0ea8da1ca

class GetAreaSchema(ma.SQLAlchemySchema):
    class Meta:
        # unknown = INCLUDE # 未知字段默认包含
<<<<<<< HEAD
        # unknown = EXCLUDE # 未知字段默认排除
=======
        unknown = EXCLUDE # 未知字段默认排除
>>>>>>> 735d39eb4d0c3134b62bf4fe1b7a2ca0ea8da1ca
        model = AreaModel

    areaName = ma.auto_field()
    level = ma.auto_field()
    parentId = ma.auto_field()
    hasChildren = ma.auto_field()
    field = fields.String(required=False, length=None)

getAreaSchema = GetAreaSchema()

class PutAreaSchema(ma.SQLAlchemySchema):
    class Meta:
        # unknown = INCLUDE # 未知字段默认包含
<<<<<<< HEAD
        # unknown = EXCLUDE # 未知字段默认排除
        model = AreaModel

    areaName = ma.auto_field()
    level = ma.auto_field()
    parentId = ma.auto_field()
    hasChildren = ma.auto_field()
=======
        unknown = EXCLUDE # 未知字段默认排除
        model = AreaModel

    areaName = fields.String(required=False, length=None)
    level = fields.Integer(required=False)
    parentId = fields.String(required=False, length=None)
    hasChildren = fields.Boolean(required=False)
>>>>>>> 735d39eb4d0c3134b62bf4fe1b7a2ca0ea8da1ca
    field = fields.String(required=False, length=None)

putAreaSchema = PutAreaSchema()
