<?php
  include "../models/ClienteClass.php";

class ClienteCtl
{
    private $Cliente;

    private $cliId;
    private $cliNomeRazao;
    private $cliFantasia;
    private $cliCpfCnpj;
    private $cliTipo;
    private $cliDataNascimento;
    private $cliSexo;
    private $cliRg;
    private $cliOrgaoEmissor;
    private $cliDataEmissaoRg;
    private $cliEmail;
    private $cliTelefone;
    private $cliNomePai;
    private $cliNomeMae;
    private $cliEstadoCivil;
    private $cliPpe;

    private $cliLogradouro;
    private $cliNumero;
    private $cliComplemento;
    private $cliBairro;
    private $cliCidade;
    private $cliEstado;
    private $cliCep;

    private $cliDataAlteracao;
    private $cliStatus;

    private $cliSelfie;
    private $cliDocFrente;
    private $cliDocVerso;
    private $cliCompEndereco;

    private $cliDeviceId;

    private $cliSenha;

    private $cliLoginBio;

    private $cliPushId;

    private $cliPercentMatch;

    private $retorno;
    private $mensagemRetorno;

    public function __construct()
    {
        $this->Cliente = new ClienteClass();
    }

    public function getClientePorId()
    {
        $this->Cliente->setCliId($this->getCliId());
        $resultado = $this->Cliente->getClientePorId();

        $this->setRetorno($this->Cliente->getRetorno());
        $this->setMensagemRetorno($this->Cliente->getMensagemRetorno());

        return $resultado;
    }

    public function getClientePorCpf()
    {
        $this->Cliente->setCliCpfCnpj($this->getCliCpfCnpj());
        $resultado = $this->Cliente->getClientePorCpf();

        $this->setRetorno($this->Cliente->getRetorno());
        $this->setMensagemRetorno($this->Cliente->getMensagemRetorno());

        return $resultado;
    }

    public function getClientePorCpfEmail()
    {
        $this->Cliente->setCliCpfCnpj($this->getCliCpfCnpj());
        $this->Cliente->setCliEmail($this->getCliEmail());
        $resultado = $this->Cliente->getClientePorCpfEmail();

        $this->setRetorno($this->Cliente->getRetorno());
        $this->setMensagemRetorno($this->Cliente->getMensagemRetorno());

        return $resultado;
    }

    public function getClientePorTelefone()
    {
        $this->Cliente->setCliTelefone($this->getCliTelefone());
        $resultado = $this->Cliente->getClientePorTelefone();

        $this->setRetorno($this->Cliente->getRetorno());
        $this->setMensagemRetorno($this->Cliente->getMensagemRetorno());

        return $resultado;
    }

    public function getClientePorDeviceId()
    {
        $this->Cliente->setCliDeviceId($this->getCliDeviceId());
        $resultado = $this->Cliente->getClientePorDeviceId();

        $this->setRetorno($this->Cliente->getRetorno());
        $this->setMensagemRetorno($this->Cliente->getMensagemRetorno());

        return $resultado;
    }

    public function listarTodos()
    {
        $resultado = $this->Cliente->listarTodos();

        $this->setRetorno($this->Cliente->getRetorno());
        $this->setMensagemRetorno($this->Cliente->getMensagemRetorno());

        return $resultado;
    }

    public function listarAtivos()
    {
        $resultado = $this->Cliente->listarAtivos();

        $this->setRetorno($this->Cliente->getRetorno());
        $this->setMensagemRetorno($this->Cliente->getMensagemRetorno());

        return $resultado;
    }

    public function inserir()
    {
        $resultado = null;

        if (empty($this->getCliNomeRazao())){
            $this->setRetorno('ERRO');
            $this->setMensagemRetorno('Nome do Cliente não pode estar vazio.');
            return $resultado;
        }

        if (empty($this->getCliCpfCnpj())){
            $this->setRetorno('ERRO');
            $this->setMensagemRetorno('CPF ou CNPJ não pode estar vazio.');
            return $resultado;
        }

        if (empty($this->getCliTipo())){
            $this->setRetorno('ERRO');
            $this->setMensagemRetorno('Tipo de Cliente não pode estar vazio.');
            return $resultado;
        }

        if (empty($this->getCliEmail())){
            $this->setRetorno('ERRO');
            $this->setMensagemRetorno('Email não pode estar vazio.');
            return $resultado;
        }

        if (empty($this->getCliTelefone())){
            $this->setRetorno('ERRO');
            $this->setMensagemRetorno('Telefone não pode estar vazio.');
            return $resultado;
        }

        $this->Cliente->setCliNomeRazao($this->getCliNomeRazao());
        $this->Cliente->setCliFantasia($this->getCliFantasia());
        $this->Cliente->setCliCpfCnpj($this->getCliCpfCnpj());
        $this->Cliente->setCliTipo($this->getCliTipo());
        $this->Cliente->setCliDataNascimento($this->getCliDataNascimento());
        $this->Cliente->setCliSexo($this->getCliSexo());
        $this->Cliente->setCliRg($this->getCliRg());
        $this->Cliente->setCliOrgaoEmissor($this->getCliOrgaoEmissor());
        $this->Cliente->setCliDataEmissaoRg($this->getCliDataEmissaoRg());
        $this->Cliente->setCliEmail($this->getCliEmail());
        $this->Cliente->setCliTelefone($this->getCliTelefone());
        $this->Cliente->setCliNomePai($this->getCliNomePai());
        $this->Cliente->setCliNomeMae($this->getCliNomeMae());
        $this->Cliente->setCliEstadoCivil($this->getCliEstadoCivil());
        $this->Cliente->setCliPpe($this->getCliPpe());

        $this->Cliente->setCliLogradouro($this->getCliLogradouro());
        $this->Cliente->setCliNumero($this->getCliNumero());
        $this->Cliente->setCliComplemento($this->getCliComplemento());
        $this->Cliente->setCliBairro($this->getCliBairro());
        $this->Cliente->setCliCidade($this->getCliCidade());
        $this->Cliente->setCliEstado($this->getCliEstado());
        $this->Cliente->setCliCep($this->getCliCep());

        $this->Cliente->setCliSelfie($this->getCliSelfie());
        $this->Cliente->setCliDocFrente($this->getCliDocFrente());
        $this->Cliente->setCliDocVerso($this->getCliDocVerso());
        $this->Cliente->setCliCompEndereco($this->getCliCompEndereco());

        $this->Cliente->setCliDeviceId($this->getCliDeviceId());

        $this->Cliente->setCliStatus($this->getCliStatus());

        $this->Cliente->setCliPercentMatch($this->getCliPercentMatch());

        $resultado = $this->Cliente->inserir();

        $this->setCliId($this->Cliente->getCliId());

        $this->setRetorno($this->Cliente->getRetorno());
        $this->setMensagemRetorno($this->Cliente->getMensagemRetorno());

        return $resultado;
    }

    public function editar()
    {
        $resultado = null;

        if(empty($this->getCliId())){
            $this->setRetorno('ERRO');
            $this->setMensagemRetorno('Cód. Cliente não pode estar vazio.');
            return $resultado;
        }

        if (empty($this->getCliNomeRazao())){
            $this->setRetorno('ERRO');
            $this->setMensagemRetorno('Nome do Cliente não pode estar vazio.');
            return $resultado;
        }

        if (empty($this->getCliCpfCnpj())){
            $this->setRetorno('ERRO');
            $this->setMensagemRetorno('CPF ou CNPJ não pode estar vazio.');
            return $resultado;
        }

        if (empty($this->getCliTipo())){
            $this->setRetorno('ERRO');
            $this->setMensagemRetorno('Tipo de Cliente não pode estar vazio.');
            return $resultado;
        }

        if (empty($this->getCliTelefone())){
            $this->setRetorno('ERRO');
            $this->setMensagemRetorno('Telefone não pode estar vazio.');
            return $resultado;
        }

        $this->Cliente->setCliId($this->getCliId());
        $this->Cliente->setCliNomeRazao($this->getCliNomeRazao());
        $this->Cliente->setCliFantasia($this->getCliFantasia());
        $this->Cliente->setCliCpfCnpj($this->getCliCpfCnpj());
        $this->Cliente->setCliTipo($this->getCliTipo());
        $this->Cliente->setCliDataNascimento($this->getCliDataNascimento());
        $this->Cliente->setCliSexo($this->getCliSexo());
        $this->Cliente->setCliRg($this->getCliRg());
        $this->Cliente->setCliDataEmissaoRg($this->getCliDataEmissaoRg());
        $this->Cliente->setCliOrgaoEmissor($this->getCliOrgaoEmissor());
        $this->Cliente->setCliTelefone($this->getCliTelefone());
        $this->Cliente->setCliNomePai($this->getCliNomePai());
        $this->Cliente->setCliNomeMae($this->getCliNomeMae());
        $this->Cliente->setCliEstadoCivil($this->getCliEstadoCivil());
        $this->Cliente->setCliPpe($this->getCliPpe());

        $this->Cliente->setCliLogradouro($this->getCliLogradouro());
        $this->Cliente->setCliNumero($this->getCliNumero());
        $this->Cliente->setCliComplemento($this->getCliComplemento());
        $this->Cliente->setCliBairro($this->getCliBairro());
        $this->Cliente->setCliCidade($this->getCliCidade());
        $this->Cliente->setCliEstado($this->getCliEstado());

        $this->Cliente->setCliCep(preg_replace('/[^0-9]/', '', $this->getCliCep()));

        $this->Cliente->setCliStatus($this->getCliStatus());

        $resultado = $this->Cliente->editar();

        $this->setRetorno($this->Cliente->getRetorno());
        $this->setMensagemRetorno($this->Cliente->getMensagemRetorno());

        return $resultado;
    }

    public function alterarEndereco()
    {
        $resultado = null;

        if(empty($this->getCliId())){
            $this->setRetorno('ERRO');
            $this->setMensagemRetorno('Cód. Cliente não pode estar vazio.');
            return $resultado;
        }

        if(empty($this->getCliCep())){
            $this->setRetorno('ERRO');
            $this->setMensagemRetorno('CEP não pode estar vazio.');
            return $resultado;
        }

        if(empty($this->getCliLogradouro())){
            $this->setRetorno('ERRO');
            $this->setMensagemRetorno('Endereço não pode estar vazio.');
            return $resultado;
        }

        if(empty($this->getCliCidade())){
            $this->setRetorno('ERRO');
            $this->setMensagemRetorno('Cidade não pode estar vazio.');
            return $resultado;
        }

        if(empty($this->getCliEstado())){
            $this->setRetorno('ERRO');
            $this->setMensagemRetorno('Estado não pode estar vazio.');
            return $resultado;
        }

        if(empty($this->getCliBairro())){
            $this->setRetorno('ERRO');
            $this->setMensagemRetorno('Bairro não pode estar vazio.');
            return $resultado;
        }

        $this->Cliente->setCliId($this->getCliId());

        $this->Cliente->setCliLogradouro($this->getCliLogradouro());
        $this->Cliente->setCliNumero($this->getCliNumero());
        $this->Cliente->setCliComplemento($this->getCliComplemento());
        $this->Cliente->setCliBairro($this->getCliBairro());
        $this->Cliente->setCliCidade($this->getCliCidade());
        $this->Cliente->setCliEstado($this->getCliEstado());

        $this->Cliente->setCliCep(preg_replace('/[^0-9]/', '', $this->getCliCep()));

        $resultado = $this->Cliente->alterarEndereco();

        $this->setRetorno($this->Cliente->getRetorno());
        $this->setMensagemRetorno($this->Cliente->getMensagemRetorno());

        return $resultado;
    }

    public function criarAcesso()
    {
        $this->Cliente->setCliId($this->getCliId());
        $this->Cliente->setCliEmail($this->getCliEmail());
        $this->Cliente->setCliNomeRazao($this->getCliNomeRazao());
        $this->Cliente->setCliTelefone($this->getCliTelefone());

        $resultado = $this->Cliente->criarAcesso();

        $this->setRetorno($this->Cliente->getRetorno());
        $this->setMensagemRetorno($this->Cliente->getMensagemRetorno());

        return $resultado;
    }

    public function esqueciSenha()
    {
        $this->Cliente->setCliId($this->getCliId());
        $this->Cliente->setCliEmail($this->getCliEmail());
        $this->Cliente->setCliNomeRazao($this->getCliNomeRazao());

        $resultado = $this->Cliente->esqueciSenha();

        $this->setRetorno($this->Cliente->getRetorno());
        $this->setMensagemRetorno($this->Cliente->getMensagemRetorno());

        return $resultado;
    }

    public function login()
    {
        $this->Cliente->setCliCpfCnpj($this->getCliCpfCnpj());
        $this->Cliente->setCliSenha($this->getCliSenha());

        $resultado = $this->Cliente->login();

        $this->setRetorno($this->Cliente->getRetorno());
        $this->setMensagemRetorno($this->Cliente->getMensagemRetorno());

        return $resultado;
    }

    public function loginIdDevice()
    {
        $this->Cliente->setCliDeviceId($this->getCliDeviceId());

        $resultado = $this->Cliente->loginIdDevice();

        $this->setRetorno($this->Cliente->getRetorno());
        $this->setMensagemRetorno($this->Cliente->getMensagemRetorno());

        return $resultado;
    }


    public function alteraLoginBio()
    {
        $this->Cliente->setCliId($this->getCliId());
        $this->Cliente->setCliLoginBio($this->getCliLoginBio());

        $resultado = $this->Cliente->alteraLoginBio();

        return $resultado;
    }

    public function alteraDispositivo()
    {
        $this->Cliente->setCliId($this->getCliId());
        $this->Cliente->setCliDeviceId($this->getCliDeviceId());

        $resultado = $this->Cliente->alteraDispositivo();

        return $resultado;
    }

    public function alteraSenha()
    {
        $this->Cliente->setCliId($this->getCliId());
        $this->Cliente->setCliDeviceId($this->getCliDeviceId());
        $this->Cliente->setCliSenha($this->getCliSenha());

        $resultado = $this->Cliente->alteraSenha();

        return $resultado;
    }

    public function gravaPushId()
    {
        $this->Cliente->setCliDeviceId($this->getCliDeviceId());
        $this->Cliente->setCliPushId($this->getCliPushId());

        $resultado = $this->Cliente->gravaPushId();

        return $resultado;
    }

    public function alteraSeqImagem()
    {
        $this->Cliente->setCliId($this->getCliId());
        $this->Cliente->setCliSeqImagem($this->getCliSeqImagem());

        $resultado = $this->Cliente->alteraSeqImagem();

        return $resultado;
    }

    /**
     * @return mixed
     */
    public function getCliId()
    {
        return $this->cliId;
    }

    /**
     * @param mixed $cliId
     */
    public function setCliId($cliId)
    {
        $this->cliId = $cliId;
    }

    /**
     * @return mixed
     */
    public function getCliNomeRazao()
    {
        return $this->cliNomeRazao;
    }

    /**
     * @param mixed $cliNomeRazao
     */
    public function setCliNomeRazao($cliNomeRazao)
    {
        $this->cliNomeRazao = $cliNomeRazao;
    }

    /**
     * @return mixed
     */
    public function getCliFantasia()
    {
        return $this->cliFantasia;
    }

    /**
     * @param mixed $cliFantasia
     */
    public function setCliFantasia($cliFantasia)
    {
        $this->cliFantasia = $cliFantasia;
    }

    /**
     * @return mixed
     */
    public function getCliCpfCnpj()
    {
        return $this->cliCpfCnpj;
    }

    /**
     * @param mixed $cliCpfCnpj
     */
    public function setCliCpfCnpj($cliCpfCnpj)
    {
        $this->cliCpfCnpj = $cliCpfCnpj;
    }

    /**
     * @return mixed
     */
    public function getCliTipo()
    {
        return $this->cliTipo;
    }

    /**
     * @param mixed $cliTipo
     */
    public function setCliTipo($cliTipo)
    {
        $this->cliTipo = $cliTipo;
    }

    /**
     * @return mixed
     */
    public function getCliDataNascimento()
    {
        return $this->cliDataNascimento;
    }

    /**
     * @param mixed $cliDataNascimento
     */
    public function setCliDataNascimento($cliDataNascimento)
    {
        $this->cliDataNascimento = $cliDataNascimento;
    }

    /**
     * @return mixed
     */
    public function getCliSexo()
    {
        return $this->cliSexo;
    }

    /**
     * @param mixed $cliSexo
     */
    public function setCliSexo($cliSexo)
    {
        $this->cliSexo = $cliSexo;
    }

    /**
     * @return mixed
     */
    public function getCliRg()
    {
        return $this->cliRg;
    }

    /**
     * @param mixed $cliRg
     */
    public function setCliRg($cliRg)
    {
        $this->cliRg = $cliRg;
    }

    /**
     * @return mixed
     */
    public function getCliOrgaoEmissor()
    {
        return $this->cliOrgaoEmissor;
    }

    /**
     * @param mixed $cliOrgaoEmissor
     */
    public function setCliOrgaoEmissor($cliOrgaoEmissor)
    {
        $this->cliOrgaoEmissor = $cliOrgaoEmissor;
    }

    /**
     * @return mixed
     */
    public function getCliDataEmissaoRg()
    {
        return $this->cliDataEmissaoRg;
    }

    /**
     * @param mixed $cliDataEmissaoRg
     */
    public function setCliDataEmissaoRg($cliDataEmissaoRg)
    {
        $this->cliDataEmissaoRg = $cliDataEmissaoRg;
    }

    /**
     * @return mixed
     */
    public function getCliEmail()
    {
        return $this->cliEmail;
    }

    /**
     * @param mixed $cliEmail
     */
    public function setCliEmail($cliEmail)
    {
        $this->cliEmail = $cliEmail;
    }

    /**
     * @return mixed
     */
    public function getCliTelefone()
    {
        return $this->cliTelefone;
    }

    /**
     * @param mixed $cliTelefone
     */
    public function setCliTelefone($cliTelefone)
    {
        $this->cliTelefone = $cliTelefone;
    }

    /**
     * @return mixed
     */
    public function getCliNomePai()
    {
        return $this->cliNomePai;
    }

    /**
     * @param mixed $cliNomePai
     */
    public function setCliNomePai($cliNomePai)
    {
        $this->cliNomePai = $cliNomePai;
    }

    /**
     * @return mixed
     */
    public function getCliNomeMae()
    {
        return $this->cliNomeMae;
    }

    /**
     * @param mixed $cliNomeMae
     */
    public function setCliNomeMae($cliNomeMae)
    {
        $this->cliNomeMae = $cliNomeMae;
    }

    /**
     * @return mixed
     */
    public function getCliEstadoCivil()
    {
        return $this->cliEstadoCivil;
    }

    /**
     * @param mixed $cliEstadoCivil
     */
    public function setCliEstadoCivil($cliEstadoCivil)
    {
        $this->cliEstadoCivil = $cliEstadoCivil;
    }

    /**
     * @return mixed
     */
    public function getCliPpe()
    {
        return $this->cliPpe;
    }

    /**
     * @param mixed $cliPpe
     */
    public function setCliPpe($cliPpe)
    {
        $this->cliPpe = $cliPpe;
    }

    /**
     * @return mixed
     */
    public function getCliLogradouro()
    {
        return $this->cliLogradouro;
    }

    /**
     * @param mixed $cliLogradouro
     */
    public function setCliLogradouro($cliLogradouro)
    {
        $this->cliLogradouro = $cliLogradouro;
    }

    /**
     * @return mixed
     */
    public function getCliNumero()
    {
        return $this->cliNumero;
    }

    /**
     * @param mixed $cliNumero
     */
    public function setCliNumero($cliNumero)
    {
        $this->cliNumero = $cliNumero;
    }

    /**
     * @return mixed
     */
    public function getCliComplemento()
    {
        return $this->cliComplemento;
    }

    /**
     * @param mixed $cliComplemento
     */
    public function setCliComplemento($cliComplemento)
    {
        $this->cliComplemento = $cliComplemento;
    }

    /**
     * @return mixed
     */
    public function getCliBairro()
    {
        return $this->cliBairro;
    }

    /**
     * @param mixed $cliBairro
     */
    public function setCliBairro($cliBairro)
    {
        $this->cliBairro = $cliBairro;
    }

    /**
     * @return mixed
     */
    public function getCliCidade()
    {
        return $this->cliCidade;
    }

    /**
     * @param mixed $cliCidade
     */
    public function setCliCidade($cliCidade)
    {
        $this->cliCidade = $cliCidade;
    }

    /**
     * @return mixed
     */
    public function getCliEstado()
    {
        return $this->cliEstado;
    }

    /**
     * @param mixed $cliEstado
     */
    public function setCliEstado($cliEstado)
    {
        $this->cliEstado = $cliEstado;
    }

    /**
     * @return mixed
     */
    public function getCliCep()
    {
        return $this->cliCep;
    }

    /**
     * @param mixed $cliCep
     */
    public function setCliCep($cliCep)
    {
        $this->cliCep = $cliCep;
    }

    /**
     * @return mixed
     */
    public function getCliDataAlteracao()
    {
        return $this->cliDataAlteracao;
    }

    /**
     * @param mixed $cliDataAlteracao
     */
    public function setCliDataAlteracao($cliDataAlteracao)
    {
        $this->cliDataAlteracao = $cliDataAlteracao;
    }

    /**
     * @return mixed
     */
    public function getCliStatus()
    {
        return $this->cliStatus;
    }

    /**
     * @param mixed $cliStatus
     */
    public function setCliStatus($cliStatus)
    {
        $this->cliStatus = $cliStatus;
    }

    /**
     * @return mixed
     */
    public function getCliSelfie()
    {
        return $this->cliSelfie;
    }

    /**
     * @param mixed $cliSelfie
     */
    public function setCliSelfie($cliSelfie)
    {
        $this->cliSelfie = $cliSelfie;
    }

    /**
     * @return mixed
     */
    public function getCliDocFrente()
    {
        return $this->cliDocFrente;
    }

    /**
     * @param mixed $cliDocFrente
     */
    public function setCliDocFrente($cliDocFrente)
    {
        $this->cliDocFrente = $cliDocFrente;
    }

    /**
     * @return mixed
     */
    public function getCliDocVerso()
    {
        return $this->cliDocVerso;
    }

    /**
     * @param mixed $cliDocVerso
     */
    public function setCliDocVerso($cliDocVerso)
    {
        $this->cliDocVerso = $cliDocVerso;
    }

    /**
     * @return mixed
     */
    public function getCliCompEndereco()
    {
        return $this->cliCompEndereco;
    }

    /**
     * @param mixed $cliCompEndereco
     */
    public function setCliCompEndereco($cliCompEndereco)
    {
        $this->cliCompEndereco = $cliCompEndereco;
    }

    /**
     * @return mixed
     */
    public function getCliDeviceId()
    {
        return $this->cliDeviceId;
    }

    /**
     * @param mixed $cliDeviceId
     */
    public function setCliDeviceId($cliDeviceId)
    {
        $this->cliDeviceId = $cliDeviceId;
    }

    /**
     * @return mixed
     */
    public function getCliSenha()
    {
        return $this->cliSenha;
    }

    /**
     * @param mixed $cliSenha
     */
    public function setCliSenha($cliSenha)
    {
        $this->cliSenha = $cliSenha;
    }

    /**
     * @return mixed
     */
    public function getCliLoginBio()
    {
        return $this->cliLoginBio;
    }

    /**
     * @param mixed $cliLoginBio
     */
    public function setCliLoginBio($cliLoginBio)
    {
        $this->cliLoginBio = $cliLoginBio;
    }

    /**
     * @return mixed
     */
    public function getCliPushId()
    {
        return $this->cliPushId;
    }

    /**
     * @param mixed $cliPushId
     */
    public function setCliPushId($cliPushId)
    {
        $this->cliPushId = $cliPushId;
    }

    /**
     * @return mixed
     */
    public function getRetorno()
    {
        return $this->retorno;
    }

    /**
     * @param mixed $retorno
     */
    public function setRetorno($retorno)
    {
        $this->retorno = $retorno;
    }

    /**
     * @return mixed
     */
    public function getMensagemRetorno()
    {
        return $this->mensagemRetorno;
    }

    /**
     * @param mixed $mensagemRetorno
     */
    public function setMensagemRetorno($mensagemRetorno)
    {
        $this->mensagemRetorno = $mensagemRetorno;
    }

    /**
     * @return mixed
     */
    public function getCliPercentMatch()
    {
        return $this->cliPercentMatch;
    }

    /**
     * @param mixed $cliPercentMatch
     */
    public function setCliPercentMatch($cliPercentMatch)
    {
        $this->cliPercentMatch = $cliPercentMatch;
    }


}