import 'package:flutter_test/flutter_test.dart';
import 'package:smplayer/core/infra/emby_api/emby_headers.dart';

void main() {
  group('EmbyRequestHeaders.media', () {
    test('媒体流 UA 使用基础 UA', () {
      final headers = EmbyRequestHeaders.media(
        deviceId: '6f43c257-2d5e-407e-9827-0a59d37ceb97',
        deviceName: 'TestDevice',
        token: 't',
        userId: 'u',
      );

      expect(headers['User-Agent'], EmbyRequestHeaders.userAgent);
      expect(headers['Accept'], '*/*');
      expect(headers['Accept-Language'], EmbyRequestHeaders.acceptLanguage);
    });
  });

  group('EmbyRequestHeaders.directMedia', () {
    test('播放器直连头不包含凭据或设备标识', () {
      final headers = EmbyRequestHeaders.directMedia();
      final normalizedNames = headers.keys
          .map((name) => name.toLowerCase())
          .toSet();

      expect(headers['User-Agent'], EmbyRequestHeaders.userAgent);
      expect(headers['Accept'], '*/*');
      expect(normalizedNames, isNot(contains('authorization')));
      expect(normalizedNames, isNot(contains('cookie')));
      expect(normalizedNames, isNot(contains('x-emby-token')));
      expect(normalizedNames, isNot(contains('x-mediabrowser-token')));
      expect(normalizedNames, isNot(contains('x-emby-authorization')));
      expect(normalizedNames, isNot(contains('x-emby-device-id')));
    });
  });

  group('SenPlayer 身份对齐', () {
    test('UA 为 SenPlayer 固定值', () {
      expect(EmbyRequestHeaders.userAgent, 'SenPlayer/6.2.0');
      expect(EmbyRequestHeaders.clientName, 'SenPlayer');
      expect(EmbyRequestHeaders.version, '6.1.0');
    });

    test('auth 头字面格式与 SenPlayer 身份一致', () {
      final auth = EmbyAuthHeader.build(
        deviceId: 'd',
        deviceName: 'Mac',
        token: 't',
        userId: 'u',
      );
      expect(
        auth,
        'MediaBrowser Token="t", Emby UserId="u", Client="SenPlayer", '
        'Device="Mac", DeviceId="d", Version="6.1.0"',
      );
    });
  });
}
