<?php
namespace ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Filters\EmailAccounts;

/*
File:   FilterByCosId.php
Date:   06.05.2020
Author: Tomasz Bielecki (tomasz.bi@thurdata.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 \ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Models\Account */
            if(!in_array($account->getCosId(), $this->availableCos)){
                unset($accounts[$key]);
            }
        }

        return $accounts;
    }

}