channel CIO_CreateAccount {
	out accounts(acList:List, createAccount(name:Str)) = append(acList, {
																			"name": name, 
																			"posts": nil,
																			"newFriend": null, 
																			"delReqFriend": null,
																			"newRequesting": null, 
																			"friends": nil, 
																			"requesting": nil, 
																			"requested": nil, 
																		 })
}

channel CIO_ChangeName(uid:Str) {
	out accounts.{uid}.name(prevName:Str, changeName(name)) = name
}

channel CIO_CreatePost(uid:Str) {
	out accounts.{uid}.posts(postsList:List, createPost(comment:Str)) = cons(comment:Str, postsList)
}

channel CIO_DeletePost(uid:Str) {
	out accounts.{uid}.posts(postsList:List, deletePost(pid:Str)) = remove(postsList, pid:Str)
}

channel CIO_PostRequesting(sendId:Str) {
	out accounts.{sendId}.newRequesting(preNewResuesting:Str, postRequesting(recvId:Str)) = recvId
}

channel C_AddRequesting(sendId:Str) {
	in accounts.{sendId}.newRequesting(preNewResuesting:Str, sync1(recvId:Str, sendRequested:Map, recvRequesting:Map, sendFriends:Map)) = recvId
	ref accounts.{sendId}.friends(sendFriends:Map, sync1(recvId:Str, sendRequested:Map, recvRequesting:Map, sendFriends:Map))
	ref accounts.{sendId}.requested(sendRequested:Map, sync1(recvId:Str, sendRequested:Map, recvRequesting:Map, sendFriends:Map))
	ref accounts.{recvId}.requesting(recvRequesting:Map, sync1(recvId:Str, sendRequested:Map, recvRequesting:Map, sendFriends:Map))
	
	out accounts.{sendId}.requesting(sendRequesting:Map, sync1(recvId:Str, sendRequested:Map, recvRequesting:Map, sendFriends:Map)) = if(contains(sendFriends:Map, recvId) == true,
																																		sendRequesting,
																																		insert(sendRequesting:Map, recvId:Str, true))
	out accounts.{recvId}.requested(recvRequested:Map, sync1(recvId:Str, sendRequested:Map, recvRequesting:Map, sendFriends:Map)) = if(ontains(sendFriends:Map, recvId) == true,
																																		recvRequested,
																																		insert(recvRequested:Map, sendId:Str, true))
}

channel CIO_RejectRequest(recvId:Str) {
	out accounts.{sendId}.requesting(sendRequesting:Map, rejectRequest(sendId:Str)) = delete(sendRequesting:Map, recvId:Str)
	out accounts.{recvId}.requested(recvRequested:Map, rejectRequest(sendId:Str)) = delete(recvRequested:Map, sendId:Str)
}

channel CIO_AdmitFriend(recvId:Str) {
	out accounts.{recvId}.newFriend(preNewFriend:Str, admitFriend(sendId:Str)) = sendId
}

channel C_AddFriend(recvId:Str) {
	in accounts.{recvId}.newFriend(preSendId:Str, sync2(sendId:Str, preSendTing:Map, preRecvTed:Map)) = sendId
	ref accounts.{sendId}.requesting(preSendTing:Map, sync2(sendId:Str, preSendTing:Map, preRecvTed:Map))
	ref accounts.{recvId}.requested(preRecvTed:Map, sync2(sendId:Str, preSendTing:Map, preRecvTed:Map))
	
	out accounts.{sendId}.friends(sendFriends:Map, sync2(sendId:Str, preSendTing:Map, preRecvTed:Map)) = if(contains(preSendTing:Map, recvId) == true && contains(preRecvTed:Map, sendId) == true,
																											insert(sendFriends, recvId:Str, true),
																											sendFriends)
	out accounts.{recvId}.friends(recvFriends:Map, sync2(sendId:Str, preSendTing:Map, preRecvTed:Map)) = if(contains(preSendTing:Map, recvId) == true && contains(preRecvTed:Map, sendId) == true,
																											insert(recvFriends, sendId:Str, true),
																											recvFriends)
	out accounts.{sendId}.requesting(sendRequesting:Map, sync2(sendId:Str, preSendTing:Map, preRecvTed:Map)) = if(contains(preSendTing:Map, recvId) == true && contains(preRecvTed:Map, sendId) == true,
																												delete(sendRequesting:Map, recvId:Str),
																												sendRequesting)
	out accounts.{recvId}.requested(recvRequested:Map, sync2(sendId:Str, preSendTing:Map, preRecvTed:Map)) = if(contains(preSendTing:Map, recvId) == true && contains(preRecvTed:Map, sendId) == true,
																												delete(recvRequested:Map, sendId:Str),
																												recvRequested)
}

channel CIO_DeleteFriendRequest(sendId:Str) {
	out accounts.{sendId}.delReqFriend(preDelReqFriend:Str, deleteFriend(recvId:Str)) = recvId
}

channel CIO_DeleteFriend(sendId:Str) {
	in accounts.{sendId}.delReqFriend(preRecvId:Str, sync3(recvId:Str, preSendFriends:Map, preRecvFriends:Map)) = recvId
	ref accounts.{sendId}.friends(preSendFriends:Map, sync3(recvId:Str, preSendFriends:Map, preRecvFriends:Map))
	ref accounts.{recvId}.friends(preRecvFriends:Map, sync3(recvId:Str, preSendFriends:Map, preRecvFriends:Map))
	out accounts.{sendId}.friends(sendFriends:Map, sync3(recvId:Str, preSendFriends:Map, preRecvFriends:Map)) = if(contains(preSendFriends:Map, recvId) == true || contains(preRecvFriends:Map, sendId) == true,
																												delete(sendFriends:Map, recvId:Str),
																												sendFriends)
	out accounts.{recvId}.friends(recvFriends:Map, sync3(recvId:Str, preSendFriends:Map, preRecvFriends:Map)) = if(contains(preSendFriends:Map, recvId) == true || contains(preRecvFriends:Map, sendId) == true,
																												delete(recvFriends:Map, sendId:Str),
																												recvFriends)
}