contract CiStatistics is ERC20{

    struct AA {address a;}
    struct SS {string s;}
    struct UU {uint u;}
    struct TAccounts { uint256 Index; address Wallet; uint256 Balance; uint256 Allowance; uint256 AllowanceDate; address AgentWallet;}  
   
    //----------------------------------------------------------------------------
    // Ci's public functions for statistical purposes only
    //----------------------------------------------------------------------------  
    function getAgentAccounts( address _AgentWallet )   public view returns (TAccounts[] memory){
        uint c = 0;
        for (uint v = 0; v < AccountsIndexes.length; v++) {
            if( AccountsAll[ AccountsIndexes[v] ].AgentWallet == _AgentWallet ){
                c++;
            }
        }        
        uint a = 0;
        TAccounts[] memory _AgentAccounts = new TAccounts[](c);
        for (uint i = 0; i < AccountsIndexes.length; i++) {
            if( AccountsAll[ AccountsIndexes[i] ].AgentWallet == _AgentWallet ){
                _AgentAccounts[a].Index         = AccountsAll[ AccountsIndexes[i] ].Index;
                _AgentAccounts[a].Wallet        = AccountsIndexes[i];
                _AgentAccounts[a].Balance       = AccountsAll[ AccountsIndexes[i] ].Balance;
                _AgentAccounts[a].Allowance     = AccountsAll[ AccountsIndexes[i] ].Allowance;
                _AgentAccounts[a].AllowanceDate = AccountsAll[ AccountsIndexes[i] ].AllowanceDate;
                _AgentAccounts[a].AgentWallet   = AccountsAll[ AccountsIndexes[i] ].AgentWallet;
                a++;
            }
        }        
        return _AgentAccounts;
    } 

    function getAllAccounts()                           public view returns (TAccounts[] memory){
        uint c = AccountsIndexes.length;
        TAccounts[] memory _AllAccounts = new TAccounts[](c);
        for (uint i = 0; i < c; i++) {
                _AllAccounts[i].Index         = AccountsAll[ AccountsIndexes[i] ].Index;
                _AllAccounts[i].Wallet        = AccountsIndexes[i];
                _AllAccounts[i].Balance       = AccountsAll[ AccountsIndexes[i] ].Balance;
                _AllAccounts[i].Allowance     = AccountsAll[ AccountsIndexes[i] ].Allowance;
                _AllAccounts[i].AllowanceDate = AccountsAll[ AccountsIndexes[i] ].AllowanceDate;
                _AllAccounts[i].AgentWallet   = AccountsAll[ AccountsIndexes[i] ].AgentWallet;
        }        
        return _AllAccounts;
    }  

    function getAccountByAddress( address _Wallet)      public view returns (TAccounts[] memory){
        TAccounts[] memory _AccountByAddress = new TAccounts[](1);
        _AccountByAddress[0].Index         = AccountsAll[ _Wallet ].Index;
        _AccountByAddress[0].Wallet        = _Wallet;
        _AccountByAddress[0].Balance       = AccountsAll[ _Wallet ].Balance;
        _AccountByAddress[0].Allowance     = AccountsAll[ _Wallet ].Allowance;
        _AccountByAddress[0].AllowanceDate = AccountsAll[ _Wallet ].AllowanceDate;
        _AccountByAddress[0].AgentWallet   = AccountsAll[ _Wallet ].AgentWallet;
        return _AccountByAddress;
    } 

    function getAccountByIndex( uint  i)                public view returns (TAccounts[] memory){
        TAccounts[] memory _AccountByIndex = new TAccounts[](1);
        _AccountByIndex[0].Index         = AccountsAll[ AccountsIndexes[i] ].Index;
        _AccountByIndex[0].Wallet        = AccountsIndexes[i];
        _AccountByIndex[0].Balance       = AccountsAll[ AccountsIndexes[i] ].Balance;
        _AccountByIndex[0].Allowance     = AccountsAll[ AccountsIndexes[i] ].Allowance;
        _AccountByIndex[0].AllowanceDate = AccountsAll[ AccountsIndexes[i] ].AllowanceDate;
        _AccountByIndex[0].AgentWallet   = AccountsAll[ AccountsIndexes[i] ].AgentWallet;
        return _AccountByIndex;
    }    

    function getAllAllowancersAccounts()                public view returns (TAccounts[] memory){
        uint c = 0;
        for (uint v = 0; v < AccountsIndexes.length; v++) {
            if( AccountsAll[ AccountsIndexes[v] ].Allowance > 0 && AccountsAll[ AccountsIndexes[v] ].AllowanceDate != 0 && AccountsAll[ AccountsIndexes[v] ].AllowanceDate <= block.timestamp ){
                c++;
            }
        } 
        uint a = 0;
        TAccounts[] memory _AllAllowancersAccounts = new TAccounts[](c);
        for (uint i = 0; i < AccountsIndexes.length; i++) {
            if( AccountsAll[ AccountsIndexes[i] ].Allowance > 0 && AccountsAll[ AccountsIndexes[i] ].AllowanceDate != 0 && AccountsAll[ AccountsIndexes[i] ].AllowanceDate <= block.timestamp ){
                _AllAllowancersAccounts[a].Index         = AccountsAll[ AccountsIndexes[i] ].Index;
                _AllAllowancersAccounts[a].Wallet        = AccountsIndexes[i];
                _AllAllowancersAccounts[a].Balance       = AccountsAll[ AccountsIndexes[i] ].Balance;
                _AllAllowancersAccounts[a].Allowance     = AccountsAll[ AccountsIndexes[i] ].Allowance;
                _AllAllowancersAccounts[a].AllowanceDate = AccountsAll[ AccountsIndexes[i] ].AllowanceDate;
                _AllAllowancersAccounts[a].AgentWallet   = AccountsAll[ AccountsIndexes[i] ].AgentWallet;
                a++;
            }
        }        
        return _AllAllowancersAccounts;
    } 
}
//Only for statistics purpouses
function getAgentAccounts( address _AgentWallet )   public view returns (TAccounts[] memory){
    uint c = 0;
    for (uint v = 0; v < AccountsIndexes.length; v++) {
        if( AccountsAll[ AccountsIndexes[v] ].AgentWallet == _AgentWallet ){
            c++;
        }
    }        
    uint a = 0;
    TAccounts[] memory _AgentAccounts = new TAccounts[](c);
    for (uint i = 0; i < AccountsIndexes.length; i++) {
        if( AccountsAll[ AccountsIndexes[i] ].AgentWallet == _AgentWallet ){
            _AgentAccounts[a].Index         = AccountsAll[ AccountsIndexes[i] ].Index;
            _AgentAccounts[a].Wallet        = AccountsIndexes[i];
            _AgentAccounts[a].Balance       = AccountsAll[ AccountsIndexes[i] ].Balance;
            _AgentAccounts[a].Allowance     = AccountsAll[ AccountsIndexes[i] ].Allowance;
            _AgentAccounts[a].AllowanceDate = AccountsAll[ AccountsIndexes[i] ].AllowanceDate;
            _AgentAccounts[a].AgentWallet   = AccountsAll[ AccountsIndexes[i] ].AgentWallet;
            a++;
        }
    }        
    return _AgentAccounts;
} 

//----------------------------------------------------------------------------
// Ci's public functions for statistical purposes only
//----------------------------------------------------------------------------  