DELIMITER $$

CREATE PROCEDURE inserir_utilizador(
    IN p_id_empresa INT,
    IN p_telefone VARCHAR(20),
    IN p_foto VARCHAR(255),
    IN p_nome VARCHAR(100),
    IN p_apelido VARCHAR(100),
    IN p_email VARCHAR(150),
    IN p_pass VARCHAR(255),
    IN p_perms VARCHAR(50),
    IN p_active TINYINT,
    OUT p_id_user INT
)
BEGIN
    INSERT INTO utilizadores (
        id_empresa,
        telefone,
        foto,
        nome,
        apelido,
        email,
        pass,
        perms,
        active
    ) VALUES (
        p_id_empresa,
        p_telefone,
        p_foto,
        p_nome,
        p_apelido,
        p_email,
        p_pass,
        p_perms,
        p_active
    );

    -- Retorna o ID gerado
    SET p_id_user = LAST_INSERT_ID();
END$$

DELIMITER ;
