import { wireChannel } from '#pikku'
import {
  onCardsConnect,
  onCardsDisconnect,
  onCardsEcho,
  onCardsSetSession,
  onCardsGetSession,
  onCardsClearSession,
} from '../functions/cards-channel.function.js'

wireChannel({
  name: 'cards',
  route: '/cards/live',
  auth: false,
  onConnect: onCardsConnect,
  onDisconnect: onCardsDisconnect,
  // Route messages by `action` so pikku JSON-parses the frame + dispatches
  // to the right handler. Frames look like `{action:'echo', text:'…'}`.
  onMessageWiring: {
    action: {
      echo: { func: onCardsEcho },
      setSession: { func: onCardsSetSession },
      getSession: { func: onCardsGetSession },
      clearSession: { func: onCardsClearSession },
    },
  },
  tags: ['kanban'],
})
