<?php

namespace Benhauer\Salesmanago\Model;

use \SALESmanago\Model\LoginInterface;
use \Benhauer\Salesmanago\Model\AbstractModel as SalesmanagoAbstractModel;

class Login extends SalesmanagoAbstractModel implements LoginInterface
{
    public function insert($settings)
    {
        $this
            ->setClientId($settings[self::C_CLIENT_ID])
            ->setSHA($settings[self::C_SHA])
            ->setApiKey($settings[self::C_API_KEY])
            ->setOwner($settings[self::OWNER])
            ->setEndpoint($settings[self::C_ENDPOINT])
            ->setToken($settings[self::C_TOKEN]);

        $this->setDefaultAdditionalDataAfterInit();

        $this->clearCache();
    }

    public function updateProperties($settings, $properties)
    {
        $this
            ->setClientId($settings[self::C_CLIENT_ID])
            ->setSHA($settings[self::C_SHA])
            ->setApiKey($settings[self::C_API_KEY])
            ->setOwner($settings[self::OWNER])
            ->setEndpoint($settings[self::C_ENDPOINT])
            ->setToken($settings[self::C_TOKEN])
            ->setLang($properties[self::C_LANG])
            ->setColors($properties[self::C_COLOR]);

        $this->setDefaultAdditionalDataAfterInit();

        $this->clearCache();
    }

    public function checkUser($settings)
    {
        $clientId = $this->getClientId();
        return !empty($clientId) ? $clientId : false;
    }
}
