module Edfiable
  extend ActiveSupport::Concern

  included do
    attr_accessor :skip_edfiable

    after_commit :schedule_stash, unless: :skip_edfiable
    before_destroy :destroy_stash, unless: :skip_edfiable
  end

  private
    def schedule_stash
      stash_service(:save)
    end

    def destroy_stash
      stash_service(:delete)
    end

    def stash_service(method)
      return unless school.ed_fi_system_wisconsin?

      Internal::Edfi::StashService.call(school, id, method, legacy_class_name)
    end
end
