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

class TeamsNotifier extends AbstractNotifier {
	public static function type(): string        { return 'teams'; }
	public static function label(): string       { return 'Microsoft Teams'; }
	public static function description(): string { return 'Post to a Teams channel via Incoming Webhook'; }

	public static function config_schema(): array {
		return [
			[ 'key' => 'webhook_url', 'label' => 'Webhook URL', 'type' => 'password', 'secret' => true, 'required' => true,
			  'help' => 'Teams channel → Connectors → Incoming Webhook' ],
		];
	}

	public function send( array $config, array $payload ): void {
		$color = $payload['level'] === 'error' ? 'E11D48' : '10B981';

		// Teams MessageCard format
		$this->post_json( $config['webhook_url'], [
			'@type'      => 'MessageCard',
			'@context'   => 'https://schema.org/extensions',
			'themeColor' => $color,
			'summary'    => $payload['title'],
			'title'      => $payload['title'],
			'text'       => $payload['message'],
			'sections'   => [[
				'facts' => [
					[ 'name' => 'Backup ID', 'value' => $payload['context']['backup_id'] ?? 'n/a' ],
					[ 'name' => 'Site',      'value' => $payload['context']['site_url']  ?? 'n/a' ],
					[ 'name' => 'Size',      'value' => size_format( $payload['context']['size'] ?? 0 ) ],
				],
			]],
		] );
	}
}
