import { EventEmitter } from 'events'

// BullMQ calls defineCommand + info internally — provide stubs
function defineCommandStub(_name: string, _opts: any) {
  return undefined
}

class MockRedis extends EventEmitter {
  // ===== BullMQ compatibility =====
  defineCommand = defineCommandStub
  info() { return Promise.resolve('# Server\r\nredis_version:7.0.0\r\n') }
  options = { keyPrefix: '', host: 'localhost', port: 6379 }
  // =====

  constructor() { super(); this.setMaxListeners(100) }
  connect() { return Promise.resolve() }
  disconnect() { return Promise.resolve(); this.removeAllListeners() }
  quit() { return Promise.resolve(); this.removeAllListeners() }
  duplicate() { return new MockRedis() }
  get() { return Promise.resolve(null) }
  set() { return Promise.resolve('OK') }
  del() { return Promise.resolve(0) }
  incr() { return Promise.resolve(1) }
  expire() { return Promise.resolve(1) }
  keys() { return Promise.resolve([]) }
  exists() { return Promise.resolve(0) }
  ttl() { return Promise.resolve(-1) }
  setnx() { return Promise.resolve(1) }
  hset() { return Promise.resolve(1) }
  hget() { return Promise.resolve(null) }
  hdel() { return Promise.resolve(0) }
  sadd() { return Promise.resolve(1) }
  srem() { return Promise.resolve(0) }
  smembers() { return Promise.resolve([]) }
  zadd() { return Promise.resolve(1) }
  zrem() { return Promise.resolve(0) }
  zrange() { return Promise.resolve([]) }
  zcard() { return Promise.resolve(0) }
  zrangebyscore() { return Promise.resolve([]) }
  lpush() { return Promise.resolve(1) }
  rpush() { return Promise.resolve(1) }
  lpop() { return Promise.resolve(null) }
  rpop() { return Promise.resolve(null) }
  llen() { return Promise.resolve(0) }
  lrange() { return Promise.resolve([]) }
  lrem() { return Promise.resolve(0) }
  publish() { return Promise.resolve(0) }
  subscribe() { return Promise.resolve() }
  unsubscribe() { return Promise.resolve() }
  xadd() { return Promise.resolve('1-0') }
  xread() { return Promise.resolve(null) }
  xgroup() { return Promise.resolve('OK') }
  xreadgroup() { return Promise.resolve(null) }
  xack() { return Promise.resolve(1) }
  xpending() { return Promise.resolve([]) }
  xrange() { return Promise.resolve([]) }
  xtrim() { return Promise.resolve(0) }
  xlen() { return Promise.resolve(0) }
  xdel() { return Promise.resolve(0) }
  xautoclaim() { return Promise.resolve([]) }
  xinfo() { return Promise.resolve({}) }
  call() { return Promise.resolve(null) }
  eval() { return Promise.resolve(1) }
  multi() { return new MockMulti() }
  exec() { return Promise.resolve([]) }
  watch() { return Promise.resolve('OK') }
  unwatch() { return Promise.resolve('OK') }
  pipeline() { return { exec: () => Promise.resolve([]) } }
  brpoplpush() { return Promise.resolve(null) }
  status = 'ready'
}

class MockMulti {
  get() { return this }
  set() { return this }
  del() { return this }
  incr() { return this }
  expire() { return this }
  exec() { return Promise.resolve([]) }
}

export default MockRedis
