import 'package:json_annotation/json_annotation.dart';

part 'get_ticker_nav_response.g.dart';

/// The filtered ticker page tree from `GET /api/mobile/v1/ticker/pages`.
///
/// The backend already drops unpublished pages, pages the user may not see, and
/// CONTENT pages without ProseMirror JSON — the app renders whatever arrives.
@JsonSerializable(explicitToJson: true)
class TickerNavResponse {
  @JsonKey(defaultValue: 1)
  final int schemaVersion;

  @JsonKey(defaultValue: '')
  final String navHash;

  @JsonKey(defaultValue: [])
  final List<TickerNavSection> sections;

  TickerNavResponse({
    required this.schemaVersion,
    required this.navHash,
    required this.sections,
  });

  factory TickerNavResponse.fromJson(Map<String, dynamic> json) =>
      _$TickerNavResponseFromJson(json);
  Map<String, dynamic> toJson() => _$TickerNavResponseToJson(this);
}

@JsonSerializable(explicitToJson: true)
class TickerNavSection {
  @JsonKey(defaultValue: '')
  final String title;

  @JsonKey(defaultValue: [])
  final List<TickerNavPage> pages;

  TickerNavSection({required this.title, required this.pages});

  factory TickerNavSection.fromJson(Map<String, dynamic> json) =>
      _$TickerNavSectionFromJson(json);
  Map<String, dynamic> toJson() => _$TickerNavSectionToJson(this);
}

/// A single navigable page. [kind] is one of `CONTENT`, `REDIRECT`,
/// `PROXIED_FILE` (see [TickerPageKind]); the extra fields are populated per
/// kind (REDIRECT → [externalUrl], PROXIED_FILE → [fileUrl]).
@JsonSerializable()
class TickerNavPage {
  @JsonKey(defaultValue: '')
  final String title;

  @JsonKey(defaultValue: '')
  final String slug;

  @JsonKey(defaultValue: 'CONTENT')
  final String kind;

  final String? hash;
  final String? externalUrl;
  final bool? externalUrlNewTab;
  final String? fileUrl;

  TickerNavPage({
    required this.title,
    required this.slug,
    required this.kind,
    this.hash,
    this.externalUrl,
    this.externalUrlNewTab,
    this.fileUrl,
  });

  factory TickerNavPage.fromJson(Map<String, dynamic> json) =>
      _$TickerNavPageFromJson(json);
  Map<String, dynamic> toJson() => _$TickerNavPageToJson(this);
}
