"use strict";
// ------------------------------------------------------------------ //
// Read queries                                                       //
// ------------------------------------------------------------------ //
Object.defineProperty(exports, "__esModule", { value: true });
exports.GET_PROVIDER_DATA = exports.SEED_INVOCATION_ROLE = exports.SEED_CONFIG_ROLE = exports.SEED_WORKFLOW_CONFIG = exports.DELETE_WORKFLOW = exports.INSERT_INVOCATION_ROLE = exports.DELETE_INVOCATION_ROLES = exports.INSERT_CONFIG_ROLE = exports.DELETE_CONFIG_ROLES = exports.UPSERT_WORKFLOW = exports.ENSURE_ROLE_EXISTS = exports.LIST_ALL_INVOCATION_ROLES = exports.LIST_ALL_ROLES = exports.LIST_ALL_WORKFLOWS = exports.GET_WORKFLOW_INVOCATION_ROLES = exports.GET_WORKFLOW_ROLES = exports.GET_WORKFLOW = void 0;
exports.GET_WORKFLOW = `\
SELECT * FROM lt_config_workflows WHERE workflow_type = $1`;
exports.GET_WORKFLOW_ROLES = `\
SELECT role FROM lt_config_roles WHERE workflow_type = $1 ORDER BY role`;
exports.GET_WORKFLOW_INVOCATION_ROLES = `\
SELECT role FROM lt_config_invocation_roles WHERE workflow_type = $1 ORDER BY role`;
exports.LIST_ALL_WORKFLOWS = `\
SELECT * FROM lt_config_workflows ORDER BY workflow_type`;
exports.LIST_ALL_ROLES = `\
SELECT * FROM lt_config_roles ORDER BY workflow_type, role`;
exports.LIST_ALL_INVOCATION_ROLES = `\
SELECT * FROM lt_config_invocation_roles ORDER BY workflow_type, role`;
// ------------------------------------------------------------------ //
// Write / upsert queries                                             //
// ------------------------------------------------------------------ //
exports.ENSURE_ROLE_EXISTS = `\
INSERT INTO lt_roles (role) VALUES ($1) ON CONFLICT DO NOTHING`;
exports.UPSERT_WORKFLOW = `\
INSERT INTO lt_config_workflows
  (workflow_type, invocable, task_queue, default_role, description, consumes, envelope_schema, resolver_schema, cron_schedule, tool_tags, execute_as)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)
ON CONFLICT (workflow_type) DO UPDATE SET
  invocable = EXCLUDED.invocable,
  task_queue = EXCLUDED.task_queue,
  default_role = EXCLUDED.default_role,
  description = EXCLUDED.description,
  consumes = EXCLUDED.consumes,
  envelope_schema = EXCLUDED.envelope_schema,
  resolver_schema = EXCLUDED.resolver_schema,
  cron_schedule = EXCLUDED.cron_schedule,
  tool_tags = EXCLUDED.tool_tags,
  execute_as = EXCLUDED.execute_as`;
exports.DELETE_CONFIG_ROLES = `\
DELETE FROM lt_config_roles WHERE workflow_type = $1`;
exports.INSERT_CONFIG_ROLE = `\
INSERT INTO lt_config_roles (workflow_type, role) VALUES ($1, $2)`;
exports.DELETE_INVOCATION_ROLES = `\
DELETE FROM lt_config_invocation_roles WHERE workflow_type = $1`;
exports.INSERT_INVOCATION_ROLE = `\
INSERT INTO lt_config_invocation_roles (workflow_type, role) VALUES ($1, $2)`;
exports.DELETE_WORKFLOW = `\
DELETE FROM lt_config_workflows WHERE workflow_type = $1`;
// ------------------------------------------------------------------ //
// Seed (insert-if-absent — used at startup, DB is source of truth)   //
// ------------------------------------------------------------------ //
exports.SEED_WORKFLOW_CONFIG = `\
INSERT INTO lt_config_workflows
  (workflow_type, invocable, task_queue, default_role, description, consumes, envelope_schema, resolver_schema, cron_schedule, tool_tags, execute_as)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)
ON CONFLICT (workflow_type) DO NOTHING`;
exports.SEED_CONFIG_ROLE = `\
INSERT INTO lt_config_roles (workflow_type, role) VALUES ($1, $2)
ON CONFLICT (workflow_type, role) DO NOTHING`;
exports.SEED_INVOCATION_ROLE = `\
INSERT INTO lt_config_invocation_roles (workflow_type, role) VALUES ($1, $2)
ON CONFLICT (workflow_type, role) DO NOTHING`;
// ------------------------------------------------------------------ //
// Provider queries                                                   //
// ------------------------------------------------------------------ //
exports.GET_PROVIDER_DATA = `\
SELECT workflow_type, data, completed_at
  FROM lt_tasks
 WHERE origin_id = $1
   AND workflow_type = ANY($2)
   AND status = 'completed'
 ORDER BY completed_at DESC`;
