<?php
namespace ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Filters\EmailAccounts;

/*
File:   FilterByCosId.php
Date:   06.05.2020
Author: Tomasz Bielecki (tomasz.bi@modulesgarden.com)
Class FilterByCosId
*/

class FilterByCosId
{
    protected $availableCos = [];

    public function setAvailableCoses($availableCoses = [])
    {
        $this->availableCos = $availableCoses;
        return $this;
    }

    public function filter($accounts = [])
    {

        foreach($accounts as $key => $account)
        {
            /* @var $account \ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Models\Account */
            if(!in_array($account->getCosId(), $this->availableCos)){
                unset($accounts[$key]);
            }
        }

        return $accounts;
    }

}