class Pass(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    school = db.Column(db.String(64), nullable=True, default=None)
    pass_time = db.Column(db.DateTime, default=datetime.now)

    deal_seed = db.Column(db.String(100), db.ForeignKey('school.seed'))
    dealer = db.relationship('School', back_populates='pass_table')
    academic_hash = db.Column(db.String(100), db.ForeignKey('academic.hash_value'))
    academic = db.relationship('Academic')
class Blacklist(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    deal_seed = db.Column(db.String(100), db.ForeignKey('institution.seed'))
    academic_hash = db.Column(db.String(100), db.ForeignKey('academic.hash_value'))
    student_seed = db.Column(db.String(100), db.ForeignKey('student.seed'))
    organization = db.Column(db.String(64), nullable=True, default=None)
    blacklist_time = db.Column(db.DateTime, default=datetime.now)
    reason = db.Column(db.Text)

    dealer = db.relationship('Institution', back_populates='blacklist')
    academic = db.relationship('Academic', back_populates='blacklist')
    student = db.relationship('Student', back_populates='blacklist')
class Apply(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(20))
    school = db.Column(db.String(64))
    department = db.Column(db.String(64))
    major = db.Column(db.String(64))
    in_time = db.Column(db.Date)
    out_time = db.Column(db.Date)
    type = db.Column(db.String(64))
    level = db.Column(db.String(64))
    year = db.Column(db.String(10))
    apply_time = db.Column(db.DateTime, default=datetime.now)
    apply_statue = db.Column(db.Integer)  # 0未通过 1通过 2待审核
    image = db.Column(db.String(64))
    deal_time = db.Column(db.DateTime)
    remark = db.Column(db.Text)
    hash_value = db.Column(db.String(100))

    deal_seed = db.Column(db.String(100), db.ForeignKey('school.seed'))
    dealer = db.relationship('School', back_populates='apply_table')
    student_seed = db.Column(db.String(100), db.ForeignKey('student.seed'))
    student = db.relationship('Student', back_populates='apply_table')
class Academic(db.Model):
    hash_value = db.Column(db.String(100), primary_key=True)
    name = db.Column(db.String(20))
    school = db.Column(db.String(64))
    department = db.Column(db.String(64))
    major = db.Column(db.String(64))
    in_time = db.Column(db.Date)
    out_time = db.Column(db.Date)
    type = db.Column(db.String(64))
    level = db.Column(db.String(64))
    year = db.Column(db.String(10))
    status = db.Column(db.Integer, default=1)
    pass_time = db.Column(db.DateTime, default=datetime.now)
    image = db.Column(db.String(64))
    remark = db.Column(db.Text)
    dealer_seed = db.Column(db.String(100))

    student_seed = db.Column(db.String(100), db.ForeignKey('student.seed'))
    student = db.relationship('Student', back_populates='academics')
    pass_table = db.relationship('Pass', uselist=False, cascade='all, delete-orphan')
    revoke_table = db.relationship('Revoke', uselist=False, cascade='all, delete-orphan')
    blacklist = db.relationship('Blacklist', back_populates='academic')

    def to_json(self):
        jsonData = {
            "name": self.name,
            "school": self.school,
            "department": self.department,
            "major": self.major,
            "in_time": self.in_time.strftime('%Y-%m-%d'),
            "out_time": self.out_time.strftime('%Y-%m-%d'),
            "type": self.type,
            "level": self.level,
            "year": self.year,
            "pass_time": self.pass_time.strftime('%Y-%m-%d'),
            "image": self.image,
            "student_seed": self.student_seed,
            "dealer_seed": self.dealer_seed
        }

        return jsonData