import { root } from '@repo/core'
import { AnnouncementController } from '@repo/sdk'
import { useState } from 'react'

export const useAnnouncementActions = () => {
  const [markReadLoading, setMarkReadLoading] = useState(false)
  const [markReadError, setMarkReadError] = useState<Error | null>(null)

  const markRead = async (id: string) => {
    setMarkReadLoading(true)
    setMarkReadError(null)
    try {
      const announcementController = root.get(AnnouncementController)
      await announcementController.markRead({ id })
    } catch (error) {
      setMarkReadError(error as Error)
    } finally {
      setMarkReadLoading(false)
    }
  }

  return {
    markRead,
    markReadLoading,
    markReadError,
  }
}
