-- OCI GenAI chat extraction. This function returns JSON only; it never chooses tables.
CREATE OR REPLACE FUNCTION sg_game_extract_mentions(p_question IN CLOB)
  RETURN CLOB AUTHID DEFINER
IS
  v_prompt CLOB;
  v_result CLOB;
BEGIN
  v_prompt := 'Extract only game-name mentions from the user question. '
    || 'Return exactly one JSON object with keys game_mentions (array of strings) '
    || 'and scope_hint (GLOBAL, SINGLE_GAME, MULTI_GAME, ALL_GAMES, UNKNOWN). '
    || 'Do not resolve names to IDs and do not generate SQL. Question: '
    || DBMS_LOB.SUBSTR(p_question, 4000, 1);
  v_result := DBMS_CLOUD_AI.GENERATE(
    prompt => v_prompt,
    profile_name => 'SGMP_POC_OCI_GPT54MINI',
    action => 'chat'
  );
  RETURN v_result;
END;
/
