/**
 * Weather Service Headless Pool
 * Using the unified headless pool system from @things-factory/shell
 */

import { getOrCreateHeadlessPool, getAllPoolStats, HEADLESS_POOL_ARGUMENT_SETS } from '@things-factory/shell'

// Create the weather pool instance
const weatherPool = getOrCreateHeadlessPool('weather', {
  min: 1,
  max: 5,
  headless: 'new', // Keep 'new' for weather compatibility
  args: [
    ...HEADLESS_POOL_ARGUMENT_SETS.basic,
    ...HEADLESS_POOL_ARGUMENT_SETS.keychain_safe,
    ...HEADLESS_POOL_ARGUMENT_SETS.security_enhanced
  ],
  acquireTimeoutMillis: 10000,
  idleTimeoutMillis: 30000, // 30초 후 유휴 인스턴스 제거
  testOnBorrow: true,
  enableCleanup: true
})

/**
 * 헤드리스 브라우저 풀 가져오기 (싱글톤 패턴)
 */
export function getBrowserPool() {
  return {
    acquire: () => weatherPool.acquire(),
    release: (resource: any) => weatherPool.release(resource),
    drain: () => weatherPool.cleanup(),
    clear: () => weatherPool.reset()
  }
}