-- Customer-managed score policy for vector-only game identity resolution.

BEGIN
  EXECUTE IMMEDIATE q'[
    CREATE TABLE sg_game_scope_policy (
      policy_key   VARCHAR2(128) PRIMARY KEY,
      number_value NUMBER,
      text_value   VARCHAR2(4000),
      description  VARCHAR2(1000) NOT NULL,
      active_yn    CHAR(1) DEFAULT 'Y' NOT NULL,
      updated_at   TIMESTAMP(6) DEFAULT SYSTIMESTAMP NOT NULL,
      CONSTRAINT sg_game_scope_policy_active_ck CHECK (active_yn IN ('Y', 'N'))
    )]';
EXCEPTION
  WHEN OTHERS THEN
    IF SQLCODE != -955 THEN RAISE; END IF;
END;
/

MERGE INTO sg_game_scope_policy t
USING (
  SELECT 'GAME_ALIAS_MAX_COSINE_DISTANCE' AS policy_key,
         0.500000 AS number_value,
         CAST(NULL AS VARCHAR2(4000)) AS text_value,
         'Maximum cosine distance for accepting the closest independently embedded game alias.' AS description
    FROM dual
) s
ON (t.policy_key = s.policy_key)
WHEN MATCHED THEN UPDATE SET
  t.description = s.description,
  t.active_yn = 'Y',
  t.updated_at = SYSTIMESTAMP
WHEN NOT MATCHED THEN INSERT (
  policy_key, number_value, text_value, description, active_yn
) VALUES (
  s.policy_key, s.number_value, s.text_value, s.description, 'Y'
);
/

COMMENT ON TABLE sg_game_scope_policy IS
  'Customer-managed game scope policy values; changing a value requires no application deployment.';
COMMENT ON COLUMN sg_game_scope_policy.number_value IS
  'Numeric policy value. GAME_ALIAS_MAX_COSINE_DISTANCE applies to the closest alias vector.';
/
