AMI event flow, distinquish incoming, ougoing calls


I’m a programmer. I have a task related to asterisk. I didn’t do any configuration of asterisk, used a testing machine, so for me it’s dificult to find where I should dig.

I haven’t found any docs for ami events for version 1.8.11. Are there any resources?
I need to save some stats from ami events. I don’t know how to distinguish incoming and outgoing calls, because for example for incoming call there are NewChannel, Join event for client and the same for agent. How to get where is agent callId and where is clients in Bridge event?
Its not very good to make decision based on amount of number in CallId or SIP name prefix, because it can change.
Should I retrieve agent callIds at start and listen for new to detect who is who?
Should I learn configuration?

Any help will be very appreciated!