# Path: fedmsg_meta_fedora_infrastructure/fasshim.py
# def avatar_url(username, size=64, default='retro'):
#     if username in hardcoded_avatars:
#         return hardcoded_avatars[username].format(size=size)
#     openid = "http://%s.id.fedoraproject.org/" % username
#     return avatar_url_from_openid(openid, size, default)


import fedmsg.meta.base
from fedmsg_meta_fedora_infrastructure.fasshim import avatar_url
class ByCopr(AbstractCoprConglomerator):
    def matches(self, a, b, **config):
        a, b = a['msg'], b['msg']
        if a['copr'] != b['copr']:
            return False
        return True

    def get_secondary_icon(self, constituents, default):
        agents = set([m['msg']['user'] for m in constituents])
        if len(agents) == 1:
            user = constituents[0]['msg']['user']
            return avatar_url(user)
        else:
            return 'https://apps.fedoraproject.org/img/icons/copr.png'

    def get_link(self, constituents):
        owner = constituents[0]['msg']['owner']
        copr = constituents[0]['msg']['copr']
        return 'https://copr.fedoraproject.org/coprs/%s/%s/' % (owner, copr)


class ByUser(AbstractCoprConglomerator):
    def matches(self, a, b, **config):
        a, b = a['msg'], b['msg']
        if a['user'] != b['user']:
            return False
        return True

    def get_secondary_icon(self, constituents, default):
        user = constituents[0]['msg']['user']

# Path: fedmsg_meta_fedora_infrastructure/fasshim.py
# def avatar_url(username, size=64, default='retro'):
#     if username in hardcoded_avatars:
#         return hardcoded_avatars[username].format(size=size)
#     openid = "http://%s.id.fedoraproject.org/" % username
#     return avatar_url_from_openid(openid, size, default)


# Path: fedmsg_meta_fedora_infrastructure/conglomerators/copr/copr.py
import fedmsg.meta.base
from fedmsg_meta_fedora_infrastructure.fasshim import avatar_url

class ByCopr(AbstractCoprConglomerator):
    def matches(self, a, b, **config):
        a, b = a['msg'], b['msg']
        if a['copr'] != b['copr']:
            return False
        return True

    def get_secondary_icon(self, constituents, default):
        agents = set([m['msg']['user'] for m in constituents])
        if len(agents) == 1:
            user = constituents[0]['msg']['user']
            return avatar_url(user)
        else:
            return 'https://apps.fedoraproject.org/img/icons/copr.png'

    def get_link(self, constituents):
        owner = constituents[0]['msg']['owner']
        copr = constituents[0]['msg']['copr']
        return 'https://copr.fedoraproject.org/coprs/%s/%s/' % (owner, copr)


class ByUser(AbstractCoprConglomerator):
    def matches(self, a, b, **config):
        a, b = a['msg'], b['msg']
        if a['user'] != b['user']:
            return False
        return True

    def get_secondary_icon(self, constituents, default):
        user = constituents[0]['msg']['user']

        return avatar_url(user)