<%#
 Copyright 2022 the original author or authors from the PyHipster project.

 This file is part of the PyHipster project, see https://github.com/pyhipster/generator-pyhipster
 for more information.

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

      https://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
-%>
from typing import List
from DatabaseConfig import db


class <%= asEntity('Authority') %>(db.Model):
    __tablename__ = "<%= jhiTablePrefix %>_authority"
    name = db.Column(db.String(80), primary_key=True)

    def __init__(self, **kwargs):
        for key, value in kwargs.items():
            self.key = value

    def get_name(self):
        return self.name

    def set_name(self, _name):
        self.name = _name
        
    def __repr__(self):
        return '<Authority %r>' % self.name

    @classmethod
    def get_by_name(cls, name) -> "Authority":
        authority = cls.query.filter_by(name=name).first() 
        return authority

    @classmethod
    def get_all_authorities(cls) -> List["Authority"]:
        authorities = cls.query.all()
        return authorities

    def save_to_db(self) -> None:
        db.session.add(self)
        db.session.commmit()

    def delete_from_db(self) -> None:
        db.session.delete(self)
        db.session.commit()

