package notification import ( "context" "fmt" "time" "lincodex/backend/internal/domain" "lincodex/backend/internal/port/outbound" ) // invitationNoticeRights checks the notice that tells a candidate about a // delivered invitation: the standing it reads is the one the rule in // domain.Delivery.CheckInvitationNotice decides on. type invitationNoticeRights struct{} // NewInvitationNoticeRights returns the rights check of invitation notices. func NewInvitationNoticeRights() SubjectRights { return invitationNoticeRights{} } func (invitationNoticeRights) Subject() domain.MailSubjectKind { return domain.MailSubjectInvitation } func (invitationNoticeRights) Check(ctx context.Context, unit outbound.UnitOfWork, delivery domain.Delivery, at time.Time) (domain.DeliveryCancelReason, error) { subject := delivery.Subject() standing, err := unit.NotificationRights().InvitationNoticeStanding(ctx, delivery.RecipientUserID(), subject.ID(), subject.OrganizationID()) if err != nil { return "", fmt.Errorf("invitationNoticeRights.Check - read standing: %w", err) } return delivery.CheckInvitationNotice(standing, at), nil }