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

from TimeConvert import TimeConvert as tc

from group.models import GroupInfo, GroupUserInfo


def is_group_admin(group_id, admin_id):
    return GroupUserInfo.objects.filter(group_id=group_id, user_id=admin_id, admin=True, admin_status=True, status=True).exists()


def is_group_subadmin(group_id, admin_id):
    return GroupUserInfo.objects.filter(group_id=group_id, user_id=admin_id, subadmin=True, admin_status=True, status=True).exists()


def have_active_group(user_id):
    groups = GroupUserInfo.objects.filter(user_id=user_id, subadmin=True, admin_status=True, status=True)
    groupids = [group.group_id for group in groups]
    return GroupInfo.objects.filter(group_id__in=groupids, group_closed=False, status=True, ended_at__gt=tc.utc_datetime()).exists()
