import type { GroupMemberAction } from '@/lib/groups/groupMemberRole'

/** DB / WS 通知 type，由前端 i18n `notifications.group.*` 解析 */
export type GroupUserNotificationType =
    | 'group_transfer_leader_target'
    | 'group_transfer_leader_broadcast'
    | 'group_promote_deputy'
    | 'group_demote_member'
    | 'group_kick'
    | 'group_apply_approved'

export type GroupNotificationParams = {
    groupName: string
    actorName: string
    targetName?: string
}

export type UserNotificationWsPayload = {
    id: string
    type: GroupUserNotificationType | string
    title: string
    content: string
    url: string | null
    isRead: boolean
    createdAt: number
    params?: GroupNotificationParams
    /** 使用者是否開啟此類型的推送設定 */
    pushEnabled?: boolean
    /** 使用者是否開啟桌面通知 */
    desktopEnabled?: boolean
}

export function isGroupMemberNotifyAction(
    action: string
): action is GroupMemberAction {
    return (
        action === 'transfer_leader' ||
        action === 'promote_deputy' ||
        action === 'demote_member' ||
        action === 'kick'
    )
}
