'''
Author: your name
Date: 2021-07-15 09:33:39
LastEditTime: 2021-07-15 17:10:06
LastEditors: Please set LastEditors
Description: In User Settings Edit
FilePath: \evm-store\tools\build_out\models\annex.20210715101849.py
'''
#!/usr/bin/env python
# -*- coding: utf_8 -*-

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

class AnnexModel(PrimaryModel):
    __tablename__ = 'evm_annex'

    app = db.Column(db.Integer, nullable = False)
    title = db.Column(db.String(100), index = True, nullable = False, default = '')
    path = db.Column(db.String(256), index = True, nullable = False, default = '')
    size = db.Column(db.Integer, nullable = True)

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

    def __init__(self, app, title, path, size, create_by=None, create_at=None, update_by=None, update_at=None):
        self.app = app
        self.title = title
        self.path = path
        self.size = size
        self.create_by = create_by
        self.create_at = create_at
        self.update_by = update_by
        self.update_at = update_at

    def __repr__(self):
        return '<AnnexModel %r>' % (self.app)

    def to_dict(self):
        return {
            'app': self.app,
            'title': self.title,
            'path': self.path,
            'size': self.size,
        }


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


deleteAnnexSchema = DeleteAnnexSchema()

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

    page = fields.Integer(required=False)
    pageSize = fields.Integer(required=False)
    title = ma.auto_field()
    app = ma.auto_field()

getListAnnexSchema = GetListAnnexSchema()
getListAnnexsSchema = GetListAnnexSchema(many=True)

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

    app = ma.auto_field()

getAnnexSchema = GetAnnexSchema()
