-- =====================================================
-- ORBIQUANT IA - FINANCIAL SCHEMA ENUMS
-- =====================================================
-- Description: Type definitions for financial domain
-- Schema: financial
-- =====================================================

-- Tipos de wallet
CREATE TYPE financial.wallet_type AS ENUM (
  'trading',      -- Para operaciones de trading
  'investment',   -- Para cuentas PAMM
  'earnings',     -- Para ganancias/distribuciones
  'referral'      -- Para bonos de referidos
);

-- Estados de wallet
CREATE TYPE financial.wallet_status AS ENUM (
  'active',
  'frozen',
  'closed'
);

-- Tipos de transacción
-- DEPRECATED: Should be renamed to financial.wallet_transaction_type
-- Conflict: CONF-001 - Same name as investment.transaction_type
-- Migration: migrations/2026-02-03_rename_transaction_type_enums.sql
CREATE TYPE financial.transaction_type AS ENUM (
  'deposit',
  'withdrawal',
  'transfer_in',
  'transfer_out',
  'fee',
  'refund',
  'earning',
  'distribution',
  'bonus'
);

-- Estados de transacción
CREATE TYPE financial.transaction_status AS ENUM (
  'pending',
  'processing',
  'completed',
  'failed',
  'cancelled',
  'reversed'
);

-- Planes de suscripción
CREATE TYPE financial.subscription_plan AS ENUM (
  'free',
  'basic',
  'pro',
  'premium',
  'enterprise'
);

-- Estados de suscripción
CREATE TYPE financial.subscription_status AS ENUM (
  'active',
  'past_due',
  'cancelled',
  'incomplete',
  'trialing',
  'unpaid',
  'paused'
);

-- Monedas soportadas
CREATE TYPE financial.currency_code AS ENUM (
  'USD',
  'MXN',
  'EUR'
);

-- Métodos de pago
CREATE TYPE financial.payment_method AS ENUM (
  'card',
  'bank_transfer',
  'wire',
  'crypto',
  'paypal',
  'stripe'
);

-- Estados de pago
CREATE TYPE financial.payment_status AS ENUM (
  'pending',
  'processing',
  'succeeded',
  'failed',
  'cancelled',
  'refunded'
);

-- Tipos de invoice
CREATE TYPE financial.invoice_type AS ENUM (
  'subscription',
  'one_time',
  'usage'
);

-- Estados de invoice
CREATE TYPE financial.invoice_status AS ENUM (
  'draft',
  'open',
  'paid',
  'void',
  'uncollectible'
);

-- Acciones de auditoría
CREATE TYPE financial.audit_action AS ENUM (
  'created',
  'balance_updated',
  'status_changed',
  'limit_changed',
  'frozen',
  'unfrozen',
  'closed'
);

COMMENT ON TYPE financial.wallet_type IS 'Tipos de wallets en el sistema';
COMMENT ON TYPE financial.wallet_status IS 'Estados posibles de una wallet';
COMMENT ON TYPE financial.transaction_type IS 'Tipos de transacciones financieras';
COMMENT ON TYPE financial.transaction_status IS 'Estados del ciclo de vida de una transacción';
COMMENT ON TYPE financial.subscription_plan IS 'Planes de suscripción disponibles';
COMMENT ON TYPE financial.subscription_status IS 'Estados de suscripción según Stripe';
COMMENT ON TYPE financial.currency_code IS 'Códigos de moneda ISO 4217 soportados';
COMMENT ON TYPE financial.payment_method IS 'Métodos de pago aceptados';
COMMENT ON TYPE financial.payment_status IS 'Estados de procesamiento de pagos';
COMMENT ON TYPE financial.invoice_type IS 'Tipos de factura';
COMMENT ON TYPE financial.invoice_status IS 'Estados de factura';
COMMENT ON TYPE financial.audit_action IS 'Acciones auditables en wallets';
