# frozen_string_literal: true require "json" CHANNELS = %w[email sms push].freeze def handler # В реальности: читаем body запроса, определяем канал и шлём уведомление # Здесь: симуляция отправки по всем каналам order_id = "ORD-DEMO" user_name = "Alice" amount = 129.99 results = CHANNELS.map do |ch| # Симуляция: email — всегда ок, sms — 95%, push — 90% success = case ch when "email" then true when "sms" then rand(100) < 95 when "push" then rand(100) < 90 end { channel: ch, status: success ? "sent" : "failed", message: "Order #{order_id} confirmed — total $#{amount}", recipient: "#{user_name.downcase}@notify", } end sent = results.count { |r| r[:status] == "sent" } total = results.length { status: "ok", order_id: order_id, sent: sent, failed: total - sent, channels: results, sent_at: Time.now.utc.strftime("%Y-%m-%dT%H:%M:%SZ"), }.to_json end