# vim: syntax=ruby:expandtab:shiftwidth=2:softtabstop=2:tabstop=2
#
# Copyright (c) 2025-present, Facebook, Inc.
# All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
provides :fb_notify_merger
default_action :merge
property :_update, :is => [TrueClass, FalseClass], :default => false, :required => false
property :_merged, :is => [TrueClass, FalseClass], :default => false, :required => false

action :update do
  if new_resource._merged
    fail 'update was called against an already-merged notify_merger!'
  end
  new_resource._update = true
end

action :merge do
  if new_resource._merged
    fail 'merge was called against an already-merged notify_merger!'
  end

  if new_resource._update
    converge_by("merging notifications for #{new_resource}") do
      new_resource._merged = true
    end
  end
end
