enum ContactsSortMethod
{
	ByTime = 0,
	ByName = 1,
}

class DialerContactDataView extends ScriptableDataView
{
	private var m_compareBuilder : CompareBuilder;
	var m_sortMethod : ContactsSortMethod;

	public function Setup()
	{
		m_compareBuilder = CompareBuilder.Make();
		m_sortMethod = ContactsSortMethod.ByName;
	}

	public override function SortItem( left : IScriptable, right : IScriptable ) : Bool
	{
		var leftData : ContactData;
		var rightData : ContactData;
		leftData = ( ( ContactData )( left ) );
		rightData = ( ( ContactData )( right ) );
		m_compareBuilder.Reset();
		return ( ( m_sortMethod == ContactsSortMethod.ByTime ) ? ( SortByTime( leftData, rightData ) ) : ( SortByName( leftData, rightData ) ) );
	}

	public override function FilterItem( data : IScriptable ) : Bool
	{
		return true;
	}

	private function SortByTime( leftData : weak< ContactData >, rightData : weak< ContactData > ) : Bool
	{
		return m_compareBuilder.BoolTrue( leftData.questRelated, rightData.questRelated ).BoolTrue( leftData.hasQuestImportantReply, rightData.hasQuestImportantReply ).GameTimeDesc( leftData.timeStamp, rightData.timeStamp ).GetBool();
	}

	private function SortByName( leftData : weak< ContactData >, rightData : weak< ContactData > ) : Bool
	{
		return m_compareBuilder.BoolTrue( leftData.questRelated, rightData.questRelated ).BoolTrue( leftData.hasQuestImportantReply, rightData.hasQuestImportantReply ).BoolTrue( leftData.isCallable, rightData.isCallable ).UnicodeStringAsc( GetLocalizedText( leftData.localizedName ), GetLocalizedText( rightData.localizedName ) ).GetBool();
	}

}

class DialerContactTemplateClassifier extends inkVirtualItemTemplateClassifier
{

	public virtual function ClassifyItem( data : Variant ) : Uint32
	{
		var contactData : ContactData;
		contactData = ( ( ContactData )( ( ( IScriptable )data ) ) );
		switch( contactData.type )
		{
			case MessengerContactType.Contact:
				return 1;
			case MessengerContactType.Fake_ShowAll:
				return 3;
			default:
				return 0;
		}
	}

}

