import { Pool } from 'pg'

/**
 * Extend products.category CHECK for partner/security/interoperability offerings.
 */
export async function up(db: Pool): Promise<void> {
  await db.query(`
    ALTER TABLE products
    DROP CONSTRAINT IF EXISTS products_category_check
  `)

  await db.query(`
    ALTER TABLE products
    ADD CONSTRAINT products_category_check
    CHECK (category IN (
      'COMPUTE',
      'NETWORK_INFRA',
      'BLOCKCHAIN_STACK',
      'BLOCKCHAIN_TOOLS',
      'FINANCIAL_MESSAGING',
      'INTERNET_REGISTRY',
      'AI_LLM_AGENT',
      'LEDGER_SERVICES',
      'IDENTITY_SERVICES',
      'WALLET_SERVICES',
      'ORCHESTRATION_SERVICES',
      'PLATFORM_SERVICES',
      'SECURITY_SERVICES',
      'INTEROPERABILITY_SERVICES'
    ))
  `)
}

export async function down(db: Pool): Promise<void> {
  await db.query(`
    ALTER TABLE products
    DROP CONSTRAINT IF EXISTS products_category_check
  `)

  await db.query(`
    ALTER TABLE products
    ADD CONSTRAINT products_category_check
    CHECK (category IN (
      'COMPUTE',
      'NETWORK_INFRA',
      'BLOCKCHAIN_STACK',
      'BLOCKCHAIN_TOOLS',
      'FINANCIAL_MESSAGING',
      'INTERNET_REGISTRY',
      'AI_LLM_AGENT',
      'LEDGER_SERVICES',
      'IDENTITY_SERVICES',
      'WALLET_SERVICES',
      'ORCHESTRATION_SERVICES',
      'PLATFORM_SERVICES'
    ))
  `)
}
