# Path: hepdata/modules/permissions/models.py
# class SubmissionParticipant(db.Model):
# 
#     """
#     This table stores information about the reviewers and
#     uploaders of a HEPData submission.
#     """
#     __tablename__ = "submissionparticipant"
# 
#     id = db.Column(db.Integer, primary_key=True,
#                    nullable=False, autoincrement=True)
# 
#     publication_recid = db.Column(db.Integer)
# 
#     full_name = db.Column(db.String(128))
#     email = db.Column(db.String(128))
#     affiliation = db.Column(db.String(128))
#     invitation_cookie = db.Column(UUIDType, default=uuid.uuid4)
# 
#     # when the user logs in with their cookie,
#     # this user_account should be updated.
#     user_account = db.Column(db.Integer, db.ForeignKey(User.id))
# 
#     # e.g., reviewer or uploader
#     role = db.Column(db.String(32), default='')
#     # e.g. primary or reserve reviewer/uploader
#     status = db.Column(db.String(32), default='reserve')
#     action_date = db.Column(db.DateTime, default=datetime.utcnow, nullable=True, index=True)


from hepdata.modules.submission.models import DataResource
from hepdata.modules.permissions.models import SubmissionParticipant
from hepdata.modules.submission.models import HEPSubmission
    :return: the HEPSubmission object or None
    """

    hepsubmissions = HEPSubmission.query.filter_by(**kwargs).all()

    last = None
    for hepsubmission in hepsubmissions:
        if last is None:
            last = hepsubmission
        else:
            if hepsubmission.version > last.version:
                last = hepsubmission

    return last


def get_submission_participants_for_record(publication_recid, roles=None, **kwargs):
    """Gets the participants for a given publication record id

    :param int publication_recid: publication_recid of a submission.
    :param ``**kwargs``: Additional filter parameters to pass to `filter_by`.
    :return: List of participants relating to that record
    :rtype: list[SubmissionParticipant]
    """
    query = SubmissionParticipant.query.filter_by(
            publication_recid=publication_recid,
            **kwargs
    )

    if roles:

# Path: hepdata/modules/permissions/models.py
# class SubmissionParticipant(db.Model):
# 
#     """
#     This table stores information about the reviewers and
#     uploaders of a HEPData submission.
#     """
#     __tablename__ = "submissionparticipant"
# 
#     id = db.Column(db.Integer, primary_key=True,
#                    nullable=False, autoincrement=True)
# 
#     publication_recid = db.Column(db.Integer)
# 
#     full_name = db.Column(db.String(128))
#     email = db.Column(db.String(128))
#     affiliation = db.Column(db.String(128))
#     invitation_cookie = db.Column(UUIDType, default=uuid.uuid4)
# 
#     # when the user logs in with their cookie,
#     # this user_account should be updated.
#     user_account = db.Column(db.Integer, db.ForeignKey(User.id))
# 
#     # e.g., reviewer or uploader
#     role = db.Column(db.String(32), default='')
#     # e.g. primary or reserve reviewer/uploader
#     status = db.Column(db.String(32), default='reserve')
#     action_date = db.Column(db.DateTime, default=datetime.utcnow, nullable=True, index=True)


# Path: hepdata/modules/submission/api.py
from hepdata.modules.submission.models import DataResource
from hepdata.modules.permissions.models import SubmissionParticipant
from hepdata.modules.submission.models import HEPSubmission

    :return: the HEPSubmission object or None
    """

    hepsubmissions = HEPSubmission.query.filter_by(**kwargs).all()

    last = None
    for hepsubmission in hepsubmissions:
        if last is None:
            last = hepsubmission
        else:
            if hepsubmission.version > last.version:
                last = hepsubmission

    return last


def get_submission_participants_for_record(publication_recid, roles=None, **kwargs):
    """Gets the participants for a given publication record id

    :param int publication_recid: publication_recid of a submission.
    :param ``**kwargs``: Additional filter parameters to pass to `filter_by`.
    :return: List of participants relating to that record
    :rtype: list[SubmissionParticipant]
    """
    query = SubmissionParticipant.query.filter_by(
            publication_recid=publication_recid,
            **kwargs
    )

    if roles:

        query = query.filter(SubmissionParticipant.role.in_(roles))