#
# Agent Relationship: An ongoing voluntary association between 2 Agents of any kind.
#

import graphene
from graphene_django.types import DjangoObjectType
import valuenetwork.api.types as types
from valuenetwork.valueaccounting.models import AgentAssociation, AgentAssociationType
from valuenetwork.api.types.AgentRelationshipRole import AgentRelationshipRole
from valuenetwork.api.models import formatAgent, Person, Organization


class AgentRelationshipCategory(graphene.Enum):
    NONE = None
    MEMBER = "member"
    PART = "part"
    PEER = "peer"
    TRADINGPARTNER = "trading partner"
    LEGALPARTNER = "legal partner"


class AgentRelationshipRole(DjangoObjectType):
    category = graphene.Field(lambda: AgentRelationshipCategory)

    class Meta:
        model = AgentAssociationType
        only_fields = ('id', 'label', 'inverse_label')

    def resolve_category(self, args, *rargs):
        return self.category


class AgentRelationship(DjangoObjectType):
    subject = graphene.Field(lambda: types.Agent)
    object = graphene.Field(lambda: types.Agent)
    relationship = graphene.Field(lambda: AgentRelationshipRole)

    class Meta:
        model = AgentAssociation
        only_fields = ('id')

    def resolve_subject(self, args, *rargs):
        return formatAgent(self.subject)

    def resolve_object(self, args, *rargs):
        return formatAgent(self.object)

    def resolve_relationship(self, args, *rargs):
        return self.relationship

#
# Agent Relationship: An ongoing voluntary association between 2 Agents of any kind.
#

import graphene
from graphene_django.types import DjangoObjectType
import valuenetwork.api.types as types
from valuenetwork.valueaccounting.models import AgentAssociation, AgentAssociationType
from valuenetwork.api.models import formatAgent, Person, Organization


class AgentRelationshipCategory(graphene.Enum):
    NONE = None
    MEMBER = "member"
    PART = "part"
    PEER = "peer"
    TRADINGPARTNER = "trading partner"
    LEGALPARTNER = "legal partner"


class AgentRelationshipRole(DjangoObjectType):
    category = graphene.Field(lambda: AgentRelationshipCategory)

    class Meta:
        model = AgentAssociationType
        only_fields = ('id', 'label', 'inverse_label')

    def resolve_category(self, args, *rargs):
        return self.category


class AgentRelationship(DjangoObjectType):
    subject = graphene.Field(lambda: types.Agent)
    object = graphene.Field(lambda: types.Agent)
    relationship = graphene.Field(lambda: AgentRelationshipRole)

    class Meta:
        model = AgentAssociation
        only_fields = ('id')

    def resolve_subject(self, args, *rargs):
        return formatAgent(self.subject)

    def resolve_object(self, args, *rargs):
        return formatAgent(self.object)

    def resolve_relationship(self, args, *rargs):
        return self.relationship

fix stupid import causing ci error