88 lines
3.9 KiB
C#

using System.ComponentModel;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using PipefyAddCompanies.Core.Services;
namespace PipefyAddCompanies.Core.Models
{
public class Empresa: INotifyPropertyChanged
{
public string Nome { get; set; } // Nome da empresa em letras maiúsculas, sem caracteres especiais
public bool? ExisteNoPipefy { get; set; } // null = não verificado, true = existe, false = não existe
public string ProspectanteEmail { get; set; } // Email do prospectante cadastrado no Pipefy
public string Cidade { get; set; } // Cidade com acentos
public string Estado { get; set; } // Estado conforme lista
public string RamoAtividade { get; set; } // Ramo de atividade da empresa
// Campos opcionais
public string? Comentarios { get; set; } // Comentários curtos
public string? TelefoneEmpresa { get; set; } // Telefone da empresa sem caracteres especiais
public string? ResponsavelEnergia { get; set; } // Nome do responsável pela energia
public string? AreaResponsavel { get; set; } // Área do responsável
public string? TelefoneResponsavel { get; set; } // Telefone do responsável (55 DDD XXXXXXXX)
public string? CelularResponsavel { get; set; } // Celular do responsável (55 DDD XXXXXXXXX)
public string? EmailResponsavel { get; set; } // Email do responsável
public string? Email2 { get; set; } // Email secundário do responsável
public string? Ambiente { get; set; } // Ambiente
public string? Distribuidora { get; set; } // Distribuidora
public decimal? ValorFatura { get; set; } // Valor da fatura, preenchido se a distribuidora estiver preenchida
public string? empresa_bd { get; set; }
public string? cidade_uf { get; set; }
public event PropertyChangedEventHandler? PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
// Método de validação para nome
public void ValidarNome()
{
Nome = Regex.Replace(Nome.ToUpper(), @"[^A-Z0-9\s]", "");
}
public Empresa(
string nome,
string prospectanteEmail,
string cidade,
string estado,
string ramoAtividade,
string comentarios,
string telefoneEmpresa,
string responsavelEnergia,
string areaResponsavel,
string telefoneResponsavel,
string celularResponsavel,
string emailResponsavel,
string email2,
string ambiente,
string distribuidora,
decimal? valorFatura = null)
{
Nome = nome.ToUpperInvariant();
ProspectanteEmail = prospectanteEmail;
Cidade = cidade;
Estado = estado;
RamoAtividade = ramoAtividade;
Comentarios = comentarios;
TelefoneEmpresa = telefoneEmpresa;
ResponsavelEnergia = responsavelEnergia;
AreaResponsavel = areaResponsavel;
TelefoneResponsavel = telefoneResponsavel;
CelularResponsavel = celularResponsavel;
EmailResponsavel= emailResponsavel;
Email2 = email2;
Ambiente = ambiente;
Distribuidora = distribuidora;
ValorFatura = distribuidora != null ? valorFatura : null;
}
public async Task AtualizarExistenciaAsync(PipefyService pipefyService)
{
ExisteNoPipefy = await pipefyService.VerificarRegistroEmpresaExistente(Nome);
OnPropertyChanged(nameof(ExisteNoPipefy)); // Notifique a mudança para que a interface reflita a atualização
}
}
}