<commit_before>import json
import logging

from channels import Group
from django.contrib.staticfiles.templatetags.staticfiles import static
from django.utils.translation import ugettext_lazy as _
from rest_framework import serializers

from lily.accounts.models import Account
from lily.calls.models import CallRecord, CallParticipant, CallTransfer
from lily.contacts.models import Contact
from lily.users.models import LilyUser


logger = logging.getLogger(__name__)
# For now outbound call integration is limted to VoIPGRID, Voys, Voys SA, Firm24, LegalThings, Converdis B.V, Converdis
OUTBOUND_ENABLED_TENANTS = [10, 50, 52, 300, 534, 601, 613]


class CallNotificationSerializer(serializers.Serializer):
    call_id = serializers.CharField()
    timestamp = serializers.DateTimeField()
    status = serializers.ChoiceField(choices=('ringing', 'in-progress', 'ended', 'warm-transfer', 'cold-transfer', ))
    direction = serializers.ChoiceField(choices=('inbound', 'outbound', ))
    caller = serializers.DictField()
    destination = serializers.DictField()

    # For transfer events.
    merged_id = serializers.CharField(required=False)
    redirector = serializers.DictField(required=False)

    def to_representation(self, instance):
        # Because the CallRecord model doesn't have the same fields DRF will complain when returning the object.
        # We don't need to return an object after creation because VG doesn't care.
        return {}

    def validate(self, data):
        if data['status'] in ['warm-transfer', 'cold-transfer', ]:
            merged_id = data.get('merged_id')
            redirector = data.get('redirector')

            if not merged_id and not redirector:
                raise serializers.ValidationError({
                    'merged_id': _('This field is required.'),
                    'redirector': _('This field is required.'),
                })
            elif not merged_id:
                raise serializers.ValidationError({<commit_msg>LILY-2952: Add Lily test tenant to the outbound call enabled tenants.<commit_after>import json
import logging

from channels import Group
from django.contrib.staticfiles.templatetags.staticfiles import static
from django.utils.translation import ugettext_lazy as _
from rest_framework import serializers

from lily.accounts.models import Account
from lily.calls.models import CallRecord, CallParticipant, CallTransfer
from lily.contacts.models import Contact
from lily.users.models import LilyUser


logger = logging.getLogger(__name__)
# For now outbound call integration is limted to VoIPGRID, Voys, Voys SA, Lily, Firm24, LegalThings, Converdis B.V, Converdis
OUTBOUND_ENABLED_TENANTS = [10, 50, 52, 130, 300, 534, 601, 613]


class CallNotificationSerializer(serializers.Serializer):
    call_id = serializers.CharField()
    timestamp = serializers.DateTimeField()
    status = serializers.ChoiceField(choices=('ringing', 'in-progress', 'ended', 'warm-transfer', 'cold-transfer', ))
    direction = serializers.ChoiceField(choices=('inbound', 'outbound', ))
    caller = serializers.DictField()
    destination = serializers.DictField()

    # For transfer events.
    merged_id = serializers.CharField(required=False)
    redirector = serializers.DictField(required=False)

    def to_representation(self, instance):
        # Because the CallRecord model doesn't have the same fields DRF will complain when returning the object.
        # We don't need to return an object after creation because VG doesn't care.
        return {}

    def validate(self, data):
        if data['status'] in ['warm-transfer', 'cold-transfer', ]:
            merged_id = data.get('merged_id')
            redirector = data.get('redirector')

            if not merged_id and not redirector:
                raise serializers.ValidationError({
                    'merged_id': _('This field is required.'),
                    'redirector': _('This field is required.'),
                })
            elif not merged_id:
                raise serializers.ValidationError({
{'fraction_non_alphanumeric': 0.09099876695437731, 'fraction_numerical': 0.011590628853267572, 'mean_word_length': 3.511679644048943, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2209080', 'n_tokens_mistral': 1162, 'n_tokens_neox': 1078, 'n_words': 331}