<?php
namespace Backreload\Notifiers;
if ( ! defined( 'ABSPATH' ) ) { exit; }

class GoogleChatNotifier extends AbstractNotifier {
	public static function type(): string        { return 'gchat'; }
	public static function label(): string       { return 'Google Chat'; }
	public static function description(): string { return 'Post to a Google Chat space via webhook'; }

	public static function config_schema(): array {
		return [
			[ 'key' => 'webhook_url', 'label' => 'Webhook URL', 'type' => 'password', 'secret' => true, 'required' => true,
			  'help' => 'Space → Manage webhooks → Add webhook' ],
		];
	}

	public function send( array $config, array $payload ): void {
		$emoji = $payload['level'] === 'error' ? '🚨' : '✅';
		$this->post_json( $config['webhook_url'], [
			'text' => "{$emoji} *{$payload['title']}*\n{$payload['message']}\n_backup_: `" . ( $payload['context']['backup_id'] ?? 'n/a' ) . "`",
		] );
	}
}
