-- 72_sgmp_select_ai_oci_genai_profile.sql
-- Run as SGMP_POC after creating SGMP_POC_OCI_DEFAULT_CRED from the local
-- ~/.oci/config DEFAULT API signing key.  No private-key material belongs in
-- this script or the repository.
--
-- The source external profile is retained.  Metadata attributes are copied
-- individually so object_list, comments, annotations and instructions remain
-- intact while external endpoint, credential and model settings are replaced.

DECLARE
  v_exists PLS_INTEGER;
BEGIN
  SELECT COUNT(*)
    INTO v_exists
    FROM user_cloud_ai_profiles
   WHERE profile_name = 'SGMP_POC_OCI_GPT54MINI';

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

  DBMS_CLOUD_AI.CREATE_PROFILE(
    profile_name => 'SGMP_POC_OCI_GPT54MINI',
    attributes   => '{
      "provider": "oci",
      "credential_name": "SGMP_POC_OCI_DEFAULT_CRED",
      "model": "openai.gpt-5.4-mini",
      "region": "us-chicago-1",
      "oci_compartment_id": "<DEFAULT tenancy OCID>"
    }',
    description  => 'Smilegate Text2SQL on OCI GenAI GPT-5.4 Mini'
  );

  FOR source_attribute IN (
    SELECT attribute_name,
           attribute_value
      FROM user_cloud_ai_profile_attributes
     WHERE profile_name = 'SGMP_POC_HAIKU45'
       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    => 'SGMP_POC_OCI_GPT54MINI',
      attribute_name  => source_attribute.attribute_name,
      attribute_value => source_attribute.attribute_value
    );
  END LOOP;
END;
/

SELECT attribute_name,
       attribute_value
  FROM user_cloud_ai_profile_attributes
 WHERE profile_name = 'SGMP_POC_OCI_GPT54MINI'
   AND attribute_name IN (
     'provider',
     'model',
     'credential_name',
     'region',
     'oci_compartment_id'
   )
 ORDER BY attribute_name;
