CREATE TABLE IF NOT EXISTS pessoa_vendedores (id INTEGER PRIMARY KEY AUTOINCREMENT,pessoa_id INTEGER NOT NULL,empresa_id INTEGER NOT NULL,grupo_pessoa_id INTEGER,tipo_vendedor TEXT NOT NULL DEFAULT 'interno',comissao_padrao NUMERIC NOT NULL DEFAULT 0,desconto_maximo NUMERIC NOT NULL DEFAULT 0,meta_mensal NUMERIC NOT NULL DEFAULT 0,data_admissao TEXT,data_desligamento TEXT,permite_desconto INTEGER NOT NULL DEFAULT 1,bloqueado INTEGER NOT NULL DEFAULT 0,motivo_bloqueio TEXT,ativo INTEGER NOT NULL DEFAULT 1,criado_em TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,atualizado_em TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,excluido_em TEXT,FOREIGN KEY(pessoa_id) REFERENCES pessoas(id),FOREIGN KEY(empresa_id) REFERENCES empresas(id),FOREIGN KEY(grupo_pessoa_id) REFERENCES grupos_pessoa(id),UNIQUE(pessoa_id,empresa_id));
CREATE INDEX IF NOT EXISTS idx_pessoa_vendedores_empresa ON pessoa_vendedores(empresa_id,ativo);
