/* Espelha o jsonb devolvido por get_company_overview(). Tudo opcional de
   proposito: empresa recem-cadastrada nao tem perfil, dominio nem integracao,
   e a ficha precisa abrir do mesmo jeito. */

export type PerfilEmpresa = {
  id?: string | null;
  store_name?: string | null;
  catalog_name?: string | null;
  slug?: string | null;
  logo_url?: string | null;
  catalog_logo_url?: string | null;
  avatar_url?: string | null;
  catalog_slogan?: string | null;
  company_description?: string | null;
  cnpj?: string | null;
  company_email?: string | null;
  company_phone?: string | null;
  phone?: string | null;
  whatsapp?: string | null;
  company_whatsapp?: string | null;
  address_zip?: string | null;
  address_street?: string | null;
  address_number?: string | null;
  address_complement?: string | null;
  address_neighborhood?: string | null;
  address_city?: string | null;
  address_state?: string | null;
  social_instagram?: string | null;
  social_facebook?: string | null;
  social_website?: string | null;
  social_tiktok?: string | null;
  social_youtube?: string | null;
  social_linkedin?: string | null;
  primary_color?: string | null;
  catalog_header_color?: string | null;
  catalog_theme?: string | null;
  catalog_noindex?: boolean | null;
  catalog_advanced_enabled?: boolean | null;
  updated_at?: string | null;
};

export type DominioProprio = {
  domain?: string | null;
  verified?: boolean | null;
  verified_at?: string | null;
  cf_ssl_status?: string | null;
  created_at?: string | null;
};

export type IntegracaoResumo = {
  provider: string;
  active?: boolean | null;
  created_at?: string | null;
  updated_at?: string | null;
  expires_at?: string | null;
};

export type UsoEmpresa = {
  produtos?: number;
  produtos_ativos?: number;
  categorias?: number;
  clientes?: number;
  pedidos?: number;
  pedidos_30d?: number;
  orcamentos?: number;
  orcamentos_30d?: number;
  pedidos_catalogo?: number;
  visitas?: number;
  visitas_30d?: number;
  recebido?: number;
  recebido_30d?: number;
  links_pagamento?: number;
  contas_pagar?: number;
  contas_receber?: number;
  caixas_pdv?: number;
  fornecedores?: number;
  equipe?: number;
};

export type AtividadeEmpresa = {
  dias_ativos_30d?: number;
  ultima_em?: string | null;
  pedidos_por_status?: Record<string, number>;
};

export type FichaEmpresa = {
  perfil?: PerfilEmpresa | null;
  dominio?: DominioProprio | null;
  integracoes?: IntegracaoResumo[] | null;
  uso?: UsoEmpresa | null;
  atividade?: AtividadeEmpresa | null;
};

export type AcessoEmpresa = {
  id: string;
  email: string;
  name: string | null;
  status: string | null;
  plan: string | null;
  planName: string | null;
  expiresAt: string | null;
  createdAt: string | null;
};

export type Nota = {
  id: string;
  note: string;
  author_email: string | null;
  created_at: string;
};

export type Evento = {
  id: string;
  action: string;
  detail: Record<string, unknown> | null;
  author_email: string | null;
  created_at: string;
};

/* A assinatura pela rota oficial da Cakto (tabela assinaturas_cakto). */
export type AssinaturaCakto = {
  cakto_subscription_id: string;
  produto_id: string | null;
  oferta_id: string;
  plano: string;
  situacao: string;
  metodo: string | null;
  pago_ate: string | null;
  proxima_cobranca: string | null;
  dias_de_credito: number | null;
  cancelar_na_cakto: boolean;
  cancelada_na_cakto_em: string | null;
  erro_ao_cancelar: string | null;
  substituida_por: string | null;
  criada_em: string;
};

export type PagamentoCakto = {
  pedido_id: string;
  ref_id: string | null;
  plano: string | null;
  valor: number | string | null;
  metodo: string | null;
  status: string;
  criado_em: string | null;
  pago_em: string | null;
};

export type FalhaCakto = {
  id: string;
  event_type: string | null;
  status: string;
  processing_details: string | null;
  tentativas: number;
  created_at: string;
};

export type DadosCakto = {
  assinaturas: AssinaturaCakto[];
  pagamentos: PagamentoCakto[];
  falhas: FalhaCakto[];
};
