package unread

// ApplyNotificationMuted applies a committed notification mute that clears and
// suppresses the member's loaded unread for one scope, and records the pre-mute
// roster baseline so mute-period messages stay uncounted.
func (s *Service) ApplyNotificationMuted(event ScopeInvalidated) error {
	if s == nil || s.runtime == nil {
		return nil
	}
	_, err := s.runtime.ApplyNotificationMuted(event)
	return err
}

// RefreshScopeRoster forces one scope roster out of the ready state, clears any
// notification-suppression markers for the given members, and queues a bounded
// reload from the store so the newly persisted notification state replaces the
// prior mute baseline and future messages regain unread eligibility.
func (s *Service) RefreshScopeRoster(workspaceID, scopeID string, scopeType ScopeType, memberIDs []string) error {
	if s == nil || s.runtime == nil || s.store == nil {
		return nil
	}
	if _, ok := s.store.(scopeRosterStore); !ok {
		return nil
	}
	if err := s.runtime.InvalidateScopeRosterForRefresh(workspaceID, scopeID, scopeType, memberIDs); err != nil {
		return err
	}
	s.enqueue(hydrateJob{
		kind:        hydrateJobRoster,
		workspaceID: workspaceID,
		scopeID:     scopeID,
		scopeType:   scopeType,
	})
	return nil
}
