import { defineTable } from 'convex/server';
import { v } from 'convex/values';

export const empresasTable = {
	empresas: defineTable({
		razao_social: v.string(),
		nome_fantasia: v.optional(v.string()),
		cnpj: v.string(),
		telefone: v.string(),
		email: v.string(),
		descricao: v.optional(v.string()),
		enderecoId: v.optional(v.id('enderecos')),
		criadoPor: v.optional(v.id('usuarios'))
	})
		.index('by_razao_social', ['razao_social'])
		.index('by_cnpj', ['cnpj']),

	contatosEmpresa: defineTable({
		empresaId: v.id('empresas'),
		nome: v.string(),
		funcao: v.string(),
		email: v.string(),
		telefone: v.string(),
		adicionadoPor: v.optional(v.id('usuarios')),
		descricao: v.optional(v.string())
	})
		.index('by_empresa', ['empresaId'])
		.index('by_email', ['email'])
};
