export const SUBSCRIBE_CHANNEL = '@@pusher/SUBSCRIBE_CHANNEL'
export const UNSUBSCRIBE_CHANNEL = '@@pusher/UNSUBSCRIBE_CHANNEL'

export interface BasePusherAction {
    channel: string
}

/**
 * Dispatch this action to subscribe to a channel
 */
export interface PusherSubscribeChannelAction extends BasePusherAction {
    type: '@@pusher/SUBSCRIBE_CHANNEL'
    events: string | string[]
    callback: (message: any) => any
}

/**
 * Dispatch this action to unsubscribe from a channel
 */
export interface PusherUnubscribeChannelAction extends BasePusherAction {
    type: '@@pusher/UNSUBSCRIBE_CHANNEL'
}

export const pusherSubscribeChannel =
    (channel: string, events: string | string[], callback: (msg: any) => any): PusherSubscribeChannelAction =>
        ({ type: SUBSCRIBE_CHANNEL, channel, events, callback })

export const pusherUnsubscribeChannel =
    (channel: string): PusherUnubscribeChannelAction =>
        ({ type: UNSUBSCRIBE_CHANNEL, channel })
