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

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

class LoginModel(PrimaryModel):
    __tablename__ = 'evm_login'

<<<<<<< HEAD
    user = db.Column(db.Integer)
    login_at = db.Column(db.String(200))
    user_agent = db.Column(db.String(200))
    ip = db.Column(db.String(128))
    geo_location = db.Column(db.String(200))
    operator = db.Column(db.String(50))
=======
    user = db.Column(db.Integer, nullable = False)
    login_at = db.Column(db.String(200), nullable = False)
    user_agent = db.Column(db.String(200), nullable = False)
    ip = db.Column(db.String(128), nullable = False)
    geo_location = db.Column(db.String(200), nullable = False)
    operator = db.Column(db.String(50), nullable = False)
>>>>>>> 735d39eb4d0c3134b62bf4fe1b7a2ca0ea8da1ca

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

    def __init__(self, user, login_at, user_agent, ip, geo_location, operator):
        self.user = user
        self.login_at = login_at
        self.user_agent = user_agent
        self.ip = ip
        self.geo_location = geo_location
        self.operator = operator

    def __repr__(self):
        return '<LoginModel %r>' % (self.user)

    def to_json(self):
        return {
            'login_at': self.login_at,
            'user_agent': self.user_agent,
            'ip': self.ip,
            'geo_location': self.geo_location,
            'operator': self.operator,
        }


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

    account = fields.String(required=True, length=64)
    password = fields.String(required=True, length=64)

postLoginSchema = PostLoginSchema()

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

    page = fields.Integer(required=False)
    pageSize = fields.Integer(required=False)
    user = ma.auto_field()
    login_at = ma.auto_field()
    user_agent = ma.auto_field()
    ip = ma.auto_field()
    geo_location = ma.auto_field()
    operator = ma.auto_field()

getListLoginSchema = GetListLoginSchema()
<<<<<<< HEAD
=======
getListLoginsSchema = GetListLoginSchema(many=True)
>>>>>>> 735d39eb4d0c3134b62bf4fe1b7a2ca0ea8da1ca

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

    user = ma.auto_field()
    login_at = ma.auto_field()
    user_agent = ma.auto_field()
    ip = ma.auto_field()
    geo_location = ma.auto_field()
    operator = ma.auto_field()

getLoginSchema = GetLoginSchema()
