import 'package:json_annotation/json_annotation.dart';

part 'get_ticker_response.g.dart';

/// The "Aktuelles" ticker post from `GET /api/mobile/v1/ticker`.
///
/// [available] is false when the current post has no ProseMirror JSON yet (a
/// legacy post not re-saved since the dual-write rollout); the backend still
/// returns 200 with `content: null` so the home surface degrades to a
/// "open in browser" hint rather than an error. Unknown/missing flags default
/// to a safe empty state.
@JsonSerializable()
class TickerResponse {
  @JsonKey(defaultValue: 1)
  final int schemaVersion;

  @JsonKey(defaultValue: false)
  final bool available;

  final String? hash;
  final String? publishedAt;

  /// Site-relative link to the web ticker (e.g. `/ticker`); the app prefixes
  /// the active Marianum-Connect base URL.
  @JsonKey(defaultValue: '/ticker')
  final String webUrl;

  /// Nested ProseMirror document (`{ type: doc, content: [...] }`) or null when
  /// [available] is false. Parsed to a `PmNode` at render time.
  final Map<String, dynamic>? content;

  TickerResponse({
    required this.schemaVersion,
    required this.available,
    this.hash,
    this.publishedAt,
    required this.webUrl,
    this.content,
  });

  factory TickerResponse.fromJson(Map<String, dynamic> json) =>
      _$TickerResponseFromJson(json);
  Map<String, dynamic> toJson() => _$TickerResponseToJson(this);
}
