#
# CDR-Stats License
# http://www.cdr-stats.org
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
#
# Copyright (C) 2011-2012 Star2Billing S.L.
#
# The Initial Developer of the Original Code is
# Arezqui Belaid <info@star2billing.com>
#
from apiplayground import APIPlayground
import datetime
import random
import time


class VoipCallAPIPlayground(APIPlayground):
    """
    To test CDR api in broswer

        ``URL`` : http://127.0.0.1:8000/api-explorer/voip-call/
    """        
    # convert s_uepoch/e_uepoch into milliseconds
    s_uepoch = datetime.datetime.now()
    start_uepoch = int(time.mktime(s_uepoch.timetuple()))
    e_uepoch = s_uepoch + datetime.timedelta(seconds=100)
    end_uepoch = int(time.mktime(e_uepoch.timetuple()))

    schema = {
        "title": "To record CDRs and bill them",
        "base_url": "http://localhost/api/v1/",
        "resources": [
            {
                "name": "/voip_call/",
                "description": "This resource allows to record CDRs and bill them.",
                "endpoints": [
                    {
                        "method": "GET",
                        "url": "/api/v1/voip_call/",
                        "description": "Returns all CDRs"
                    },
                    {
                        "method": "GET",
                        "url": "/api/v1/voip_call/{id}/",
                        "description": "Returns a specific cdr"
                    },
                    {
                        "method": "POST",
                        "url": "/api/v1/voip_call/",
                        "description": "Creates new billed voip call",
                        "parameters": [
                            {
                                "name": "switch_id",
                                "type": "string",
                                "is_required": True,
                                "default": "1"
                            },
                            {
                                "name": "caller_id_number",
                                "type": "string",
                                "default": "48092924"
                            },
                            {
                                "name": "caller_id_name",
                                "type": "string",
                                "default": "CallerName"
                            },
                            {
                                "name": "destination_number",
                                "type": "string",
                                "default": "3465778800"
                            },
                            {
                                "name": "duration",
                                "type": "string",
                                "is_required": True,
                                "default": "100"
                            },
                            {
                                "name": "billsec",
                                "type": "string",
                                "default": "90"
                            },
                            {
                                "name": "hangup_cause_id",
                                "type": "string",
                                "default": "16"
                            },
                            {
                                "name": "direction",
                                "type": "string",
                                "default": "INBOUND"
                            },
                            {
                                "name": "remote_media_ip",
                                "type": "string",
                                "default": "127.0.0.1"
                            },
                            {
                                "name": "accountcode",
                                "type": "string",
                                "default": "123456"
                            },
                            {
                                "name": "start_uepoch",
                                "type": "string",
                                "default": start_uepoch
                            },
                            {
                                "name": "answer_uepoch",
                                "type": "string",
                                "default": start_uepoch
                            },
                            {
                                "name": "end_uepoch",
                                "type": "string",
                                "default": end_uepoch
                            },
                            {
                                "name": "mduration",
                                "type": "string",
                                "default": "10000"
                            },
                            {
                                "name": "billmsec",
                                "type": "string",
                                "default": "90000"
                            },
                            {
                                "name": "read_codec",
                                "type": "string",
                                "default": "G711"
                            },
                            {
                                "name": "write_codec",
                                "type": "string",
                                "default": "G711"
                            },
                        ]
                    },
                ]
            },
        ]
    }

@@ -422,16 +422,30 @@
 yground%0A
+from datetime 
 import d
@@ -455,22 +455,19 @@
 time
-%0Aimport random
+, timedelta
 %0Aimp
@@ -632,24 +632,16 @@
 %0A    %22%22%22
-        
 %0A    # c
@@ -698,25 +698,16 @@
 epoch = 
-datetime.
 datetime
@@ -771,16 +771,16 @@
 ple()))%0A
+
     e_ue
@@ -797,25 +797,16 @@
 epoch + 
-datetime.
 timedelt

fix import on voip call api