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

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

class UserModel(PrimaryModel):
    __tablename__ = 'evm_user'

<<<<<<< HEAD
    app_name = db.Column(db.String(70), index = True)
    app_icon = db.Column(db.String(200))
    app_version = db.Column(db.String(20))
    category = db.Column(db.Integer)
    category_2th = db.Column(db.Integer)
    developer = db.Column(db.Integer)
    download_url = db.Column(db.String(20))
    app_file_size = db.Column(db.Integer)
    app_screen_size = db.Column(db.Integer)
    app_arch = db.Column(db.String(20))
    app_review = db.Column(db.String(100))
=======
    app_name = db.Column(db.String(70), index = True, nullable = False)
    app_icon = db.Column(db.String(200), nullable = False)
    app_version = db.Column(db.String(20), nullable = False)
    category = db.Column(db.Integer, nullable = False)
    category_2th = db.Column(db.Integer, nullable = False)
    developer = db.Column(db.Integer, nullable = False)
    download_url = db.Column(db.String(20), nullable = False)
    app_file_size = db.Column(db.Integer, nullable = False)
    app_screen_size = db.Column(db.Integer, nullable = False)
    app_arch = db.Column(db.String(20), nullable = False)
    app_review = db.Column(db.String(100), nullable = False)
>>>>>>> 735d39eb4d0c3134b62bf4fe1b7a2ca0ea8da1ca

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

    def __init__(self, app_name, app_icon, app_version, category, category_2th, developer, download_url, app_file_size, app_screen_size, app_arch, app_review):
        self.app_name = app_name
        self.app_icon = app_icon
        self.app_version = app_version
        self.category = category
        self.category_2th = category_2th
        self.developer = developer
        self.download_url = download_url
        self.app_file_size = app_file_size
        self.app_screen_size = app_screen_size
        self.app_arch = app_arch
        self.app_review = app_review

    def __repr__(self):
        return '<UserModel %r>' % (self.app_name)

    def to_json(self):
        return {
            'app_name': self.app_name,
            'app_icon': self.app_icon,
            'app_version': self.app_version,
            'category': self.category,
            'category_2th': self.category_2th,
            'developer': self.developer,
            'download_url': self.download_url,
            'app_file_size': self.app_file_size,
            'app_screen_size': self.app_screen_size,
            'app_arch': self.app_arch,
            'app_review': self.app_review,
        }


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

    app_name = ma.auto_field()
    app_icon = ma.auto_field()
    app_version = ma.auto_field()
    category = ma.auto_field()
    category_2th = ma.auto_field()
    developer = ma.auto_field()
    app_screen_size = ma.auto_field()
    app_arch = ma.auto_field()
    app_review = ma.auto_field()

postUserSchema = PostUserSchema()
<<<<<<< HEAD
postUsersSchema = PostUserSchema(many=True)
=======
>>>>>>> 735d39eb4d0c3134b62bf4fe1b7a2ca0ea8da1ca

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


deleteUserSchema = DeleteUserSchema()

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

    page = fields.Integer(required=False)
    pageSize = fields.Integer(required=False)
    app_name = ma.auto_field()
    app_version = ma.auto_field()
    category = ma.auto_field()
    category_2th = ma.auto_field()
    app_arch = ma.auto_field()

getListUserSchema = GetListUserSchema()
<<<<<<< HEAD
=======
getListUsersSchema = GetListUserSchema(many=True)
>>>>>>> 735d39eb4d0c3134b62bf4fe1b7a2ca0ea8da1ca

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

    app_name = ma.auto_field()
    app_version = ma.auto_field()
    category = ma.auto_field()
    category_2th = ma.auto_field()
    app_arch = ma.auto_field()

getUserSchema = GetUserSchema()

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

    app_name = ma.auto_field()
    app_icon = ma.auto_field()
    app_version = ma.auto_field()
    app_screen_size = ma.auto_field()
    app_arch = ma.auto_field()
    app_review = ma.auto_field()
    category = ma.auto_field()
    category_2th = ma.auto_field()

putUserSchema = PutUserSchema()
