-- Creates non-operational OCI profiles for game-scope extraction benchmarks.
-- Every profile inherits the active GPT profile's OCI credential, region,
-- object list, and metadata. Only model is varied.

DECLARE
  v_credential_name VARCHAR2(128);
  v_region VARCHAR2(128);
  v_compartment_id VARCHAR2(4000);
  v_attributes CLOB;
  v_attribute_json JSON_OBJECT_T;
  v_exists PLS_INTEGER;

  PROCEDURE create_candidate(
    p_profile_name IN VARCHAR2,
    p_model IN VARCHAR2
  ) IS
  BEGIN
    SELECT COUNT(*)
      INTO v_exists
      FROM user_cloud_ai_profiles
     WHERE profile_name = p_profile_name;

    IF v_exists > 0 THEN
      DBMS_CLOUD_AI.DROP_PROFILE(profile_name => p_profile_name, force => TRUE);
    END IF;

    v_attribute_json := JSON_OBJECT_T();
    v_attribute_json.put('provider', 'oci');
    v_attribute_json.put('credential_name', v_credential_name);
    v_attribute_json.put('model', p_model);
    v_attribute_json.put('region', v_region);
    v_attribute_json.put('oci_compartment_id', v_compartment_id);
    v_attributes := v_attribute_json.to_clob;

    DBMS_CLOUD_AI.CREATE_PROFILE(
      profile_name => p_profile_name,
      attributes   => v_attributes,
      description  => 'Non-operational Smilegate game-scope benchmark profile'
    );

    FOR source_attribute IN (
      SELECT attribute_name, attribute_value
        FROM user_cloud_ai_profile_attributes
       WHERE profile_name = 'SGMP_POC_OCI_GPT54MINI'
         AND attribute_name NOT IN (
           'credential_name', 'model', 'provider', 'provider_endpoint',
           'region', 'oci_compartment_id', 'oci_endpoint_id',
           'oci_apiformat', 'oci_runtimetype'
         )
    ) LOOP
      DBMS_CLOUD_AI.SET_ATTRIBUTE(
        profile_name    => p_profile_name,
        attribute_name  => source_attribute.attribute_name,
        attribute_value => source_attribute.attribute_value
      );
    END LOOP;
  END;
BEGIN
  SELECT DBMS_LOB.SUBSTR(attribute_value, 128, 1)
    INTO v_credential_name
    FROM user_cloud_ai_profile_attributes
   WHERE profile_name = 'SGMP_POC_OCI_GPT54MINI'
     AND attribute_name = 'credential_name';

  SELECT DBMS_LOB.SUBSTR(attribute_value, 128, 1)
    INTO v_region
    FROM user_cloud_ai_profile_attributes
   WHERE profile_name = 'SGMP_POC_OCI_GPT54MINI'
     AND attribute_name = 'region';

  SELECT DBMS_LOB.SUBSTR(attribute_value, 4000, 1)
    INTO v_compartment_id
    FROM user_cloud_ai_profile_attributes
   WHERE profile_name = 'SGMP_POC_OCI_GPT54MINI'
     AND attribute_name = 'oci_compartment_id';

  create_candidate('SGMP_SCOPE_COHERE_VISION', 'cohere.command-a-vision');
  create_candidate('SGMP_SCOPE_COHERE_COMMAND', 'cohere.command-latest');
  create_candidate('SGMP_SCOPE_COHERE_PLUS', 'cohere.command-plus-latest');
  create_candidate('SGMP_SCOPE_GEMINI_FLASH', 'google.gemini-2.5-flash-lite');
  create_candidate('SGMP_SCOPE_LLAMA_MAV', 'meta.llama-4-maverick-17b-128e-instruct-fp8');
  create_candidate('SGMP_SCOPE_GROK_NONR', 'xai.grok-4.20-non-reasoning');
END;
/

SELECT profile_name, attribute_value AS model
  FROM user_cloud_ai_profile_attributes
 WHERE profile_name LIKE 'SGMP_SCOPE_%'
   AND attribute_name = 'model'
 ORDER BY profile_name;
