<?php
/**
 * Created by PhpStorm.
 * User: Imac
 * Date: 24/04/2019
 * Time: 14:22
 */

namespace Actigraph\ActipageBaseBundle\Services\EspaceClient;



class EspaceClientService
{
    private $arrayInstantiateObject;
    public function  __construct($params){
        if(isset($params["espaceClient"])) {
            $config = $params["espaceClient"];
            foreach ($config as $key => $form) {
                if ($form["type"] == "commun") {
                    $path = "Actigraph\ActipageBaseBundle\Services\EspaceClient\\" . $form["service"];
                } else {
                    $path = $path = "App\Service\\" . $form["service"];

                }
                $this->arrayInstantiateObject[$key] = new $path();
            }
        }
    }

    public function validateData($data){
        $errors = array();
        foreach ($data as $key=>$formdata){
            if(isset($this->arrayInstantiateObject[$key])) {
                $result = $this->arrayInstantiateObject[$key]->validateData($data);
                if (is_array($result)) {
                    $errors = array_merge($errors, $result);
                }
            }
        }

        if(count($errors) > 0 )
            return $errors;

        return true;
    }

    public function saveData($data){
        return true;
    }

}