using System;
using System.Collections.Generic;
using System.Text;

namespace ProxyCalls
{
    public class CSSIPProxyCallsEnv : GTAPIASM.GTAPIEnv 
    {
        public Form1 m_pMainWnd;
        public String m_sForwardingAddr;

        public override void On_RecvConnected(int ch)
        {
            base.On_RecvConnected(ch);
        }

        public override void On_RecvDialing(int ch, string sCaller, string sCallee)
        {
            base.On_RecvDialing(ch, sCaller, sCallee);
        }


        public override void On_RecvOffered(int ch, string sCaller, string sCallee, string sDestAddr, string sViaAddr, string sFromIP, ushort nFromPort)
        {
            base.On_RecvOffered(ch, sCaller, sCallee, sDestAddr, sViaAddr, sFromIP, nFromPort);
        }

        public override void On_RecvIdle(int ch, int code, string desc)
        {
            base.On_RecvIdle(ch, code, desc);
        }

        public override void On_RecvRinging(int ch)
        {
            base.On_RecvRinging(ch);
        }

        public override void On_RecvRegStatus(int user_id, int status, int regtime)
        {
            base.On_RecvRegStatus(user_id, status, regtime);
        }

        public override void On_RecvDTMFKeyDown(int ch, byte keyValue, uint ticks)
        {
            base.On_RecvDTMFKeyDown(ch, keyValue, ticks);
        }

        public override void On_RecvDTMFKeyUp(int ch, byte keyValue, uint ticks)
        {
            base.On_RecvDTMFKeyUp(ch, keyValue, ticks);
        }

        public override void On_RecvDTMFDone(int ch, int doneReason, string dtmfBuf)
        {
            base.On_RecvDTMFDone(ch, doneReason, dtmfBuf);
        }

        public override void On_VoiceActivityDetected(int ch, int voice_dir, int voice_on, int level, uint reserved)
        {
            base.On_VoiceActivityDetected(ch, voice_dir, voice_on, level, reserved);
        }

        public override string On_ProxyNewCallSession(uint pid, uint sid, IntPtr msg, string authid, string fromid, string toid, string suri, string via, string saddr, ushort nport, bool bCredit)
        {
            //return base.On_ProxyNewCallSession(pid, sid, msg, authid, fromid, toid, suri, via, saddr, nport, bCredit);

            /*
            Possible return values:
            "sip:undefined" = wait until ProxySetNewCallSessionAddr is called
            Sometimes you cannot immediately decide what to do with this call, and then you can call ProxySetNewCallSessionAddr function to provide an address later.
            NOTE: The OCX(ActiveX) users should(have to) use ProxySetNewCallSessionAddr function later to provide one of the following values:
            "channel" = to channel. Default value. Then one of the channels will have On_RecvOffered event triggered.
            "unauthorized" = need credit to process. You should check the fromID, to see if it is a call from proxy site’s user(or extension of PBX). If it does, and Credit is false, then “unauthorized” string is returned to ask authorization to call out.
            "sip:123@abc.com" = with right credit or don't need credit, processed by proxy site and transfered to this address
            "|" can be used to seperate the credit info. For example: "To<sip:123@abc.com>|From<sip:456@abc.com>|User<1234>|Password<4567>"
            Otherwise, if none of above matched, refer to user's contact info.
            */

            //forward any calls to PC Best Music Server:
            return m_sForwardingAddr;
        }


    }
}
