/// 公告列表项 — POST uc/announcement/page 返回的 content 数组元素
class AnnouncementContent {
  final String id;
  final String title;
  final String content;
  final String createTime;
  final int announcementClassification;
  final String imgUrl;
  final bool isShow;
  final String isTop;
  final int sort;

  const AnnouncementContent({
    this.id = '',
    this.title = '',
    this.content = '',
    this.createTime = '',
    this.announcementClassification = 0,
    this.imgUrl = '',
    this.isShow = true,
    this.isTop = '',
    this.sort = 0,
  });

  factory AnnouncementContent.fromJson(Map<String, dynamic> json) {
    return AnnouncementContent(
      id: json['id']?.toString() ?? '',
      title: json['title']?.toString() ?? '',
      content: json['content']?.toString() ?? '',
      createTime: json['createTime']?.toString() ?? '',
      announcementClassification:
          json['announcementClassification'] as int? ?? 0,
      imgUrl: json['imgUrl']?.toString() ?? '',
      isShow: json['isShow'] as bool? ?? true,
      isTop: json['isTop']?.toString() ?? '',
      sort: json['sort'] as int? ?? 0,
    );
  }
}

/// 系统弹窗公告 — GET uc/announcement/system / GET uc/announcement/popups
class AnnouncementBean {
  final String id;
  final String title;
  final String content;
  final String createTime;
  final String imgUrl;
  final bool isShow;
  final String isTop;
  final int sort;
  final int announcementClassification;

  const AnnouncementBean({
    this.id = '',
    this.title = '',
    this.content = '',
    this.createTime = '',
    this.imgUrl = '',
    this.isShow = false,
    this.isTop = '',
    this.sort = 0,
    this.announcementClassification = 0,
  });

  factory AnnouncementBean.fromJson(Map<String, dynamic> json) {
    return AnnouncementBean(
      id: json['id']?.toString() ?? '',
      title: json['title']?.toString() ?? '',
      content: json['content']?.toString() ?? '',
      createTime: json['createTime']?.toString() ?? '',
      imgUrl: json['imgUrl']?.toString() ?? '',
      isShow: json['isShow'] as bool? ?? false,
      isTop: json['isTop']?.toString() ?? '',
      sort: json['sort'] as int? ?? 0,
      announcementClassification:
          json['announcementClassification'] as int? ?? 0,
    );
  }
}

/// 公告详情 / 帮助详情 共用模型 — GET uc/announcement/{id} 或 POST uc/ancillary/more/help/detail
class WebInfoContent {
  final String id;
  final String title;
  final String content;
  final String createTime;
  final String imgUrl;
  final String isTop;

  const WebInfoContent({
    this.id = '',
    this.title = '',
    this.content = '',
    this.createTime = '',
    this.imgUrl = '',
    this.isTop = '',
  });

  /// isTop == "0" 表示置顶
  bool get isPinned => isTop == '0';

  factory WebInfoContent.fromJson(Map<String, dynamic> json) {
    return WebInfoContent(
      id: json['id']?.toString() ?? '',
      title: json['title']?.toString() ?? '',
      content: json['content']?.toString() ?? '',
      createTime: json['createTime']?.toString() ?? '',
      imgUrl: json['imgUrl']?.toString() ?? '',
      isTop: json['isTop']?.toString() ?? '',
    );
  }
}

/// 帮助中心分组 — POST uc/ancillary/more/help
///
/// 分组标题：服务端随请求体/Header 中的 `lang` 返回本地化文案。
/// JSON 字段名为历史遗留：[titleCN] 实为「当前 lang 下的标题」（日/韩/英等均可能在此；`lang=en_US` 时常与 [titleEN] 相同）。
class HelpInfo {
  final String cate;
  final String titleEN;
  final String titleCN;
  final List<WebInfoContent> items;

  const HelpInfo({
    this.cate = '',
    this.titleEN = '',
    this.titleCN = '',
    this.items = const [],
  });

  /// 列表展示用标题（与 Web 一致：优先本地化字段 [titleCN]）。
  String get localizedGroupTitle =>
      titleCN.isNotEmpty ? titleCN : titleEN;

  factory HelpInfo.fromJson(Map<String, dynamic> json) {
    final contentList = json['content'];
    return HelpInfo(
      cate: json['cate']?.toString() ?? '',
      titleEN: json['titleEN']?.toString() ?? '',
      titleCN: json['titleCN']?.toString() ?? '',
      items: contentList is List
          ? contentList
              .whereType<Map<String, dynamic>>()
              .map((e) => WebInfoContent.fromJson(e))
              .toList()
          : const [],
    );
  }
}
