##############################################################################
# Copyright (c) 2004-2005 Black Rock City, LLC
# Copyright (c) 2004-2005 ObjectRealms, LLC
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
##############################################################################
"""
$Id: $
"""

class TeamDataBag:
    """ Carries data for a test team.  member_map = ((('member', 'status'), ('Manager', 'Member')), ) """

    mkgrp = lambda members, status, roles: [((member, status), roles) for member in members]

    def __init__(self, id, member_map):
        self.id = id
        self.member_map = member_map

    def getMemberIds(self):
        return [member for member, status in dict(self.member_map).keys()]
    
    def isMember(self, member_id):
        return member_id in self.getMemberIds()
    
    def statusList(self):
        return [status for member, status in dict(self.member_map).keys()]
    
    def statusDict(self):
        mapdict = dict(self.member_map)        
        return dict( mapdict.keys() )
    
    def rolesDict(self):
        """ roled keyed by member id """
        mapdict = dict(self.member_map)        
        return dict([ (x[0], mapdict[x]) for x in mapdict.keys()])

    def getMembersWithRole(self, role):
        ms = [ms for ms, roles in self.member_map if role in roles]
        return [member for member, status in ms]

    def getMembersByStatus(self, status):
        return [m[0] for ms, roles in self.member_map if ms[1] == status]
        
    def getRolesByMemberId(self, member_id):
        return self.RolesDict()[member_id]
        
    def getStatusByMemberId(self, member_id):
        return self.StatusDict()[member_id]

    
