class AnnouncementModel {
  final String id;
  final String title;
  final String content;
  final String contentType;
  final String type;
  final String publisherId;
  final String publisherName;
  final DateTime publishTime;
  final bool isTop;
  final int privateLevel;
  final List<String> targetDepts;
  final List<String> targetUsers;
  final bool requireConfirm;
  final DateTime expiryDate;
  final List<String> attachments;
  final int readCount;
  final int unreadCount;
  final DateTime createTime;

  const AnnouncementModel({
    required this.id,
    required this.title,
    required this.content,
    this.contentType = 'text',
    this.type = '通知公告',
    required this.publisherId,
    required this.publisherName,
    required this.publishTime,
    this.isTop = false,
    this.privateLevel = 0,
    this.targetDepts = const [],
    this.targetUsers = const [],
    this.requireConfirm = false,
    required this.expiryDate,
    this.attachments = const [],
    this.readCount = 0,
    this.unreadCount = 0,
    required this.createTime,
  });

  factory AnnouncementModel.fromJson(Map<String, dynamic> json) {
    return AnnouncementModel(
      id: json['id'] as String,
      title: json['title'] as String,
      content: json['content'] as String? ?? '',
      contentType: json['contentType'] as String? ?? 'text',
      type: json['type'] as String? ?? '通知公告',
      publisherId: json['publisherId'] as String? ?? '',
      publisherName: json['publisherName'] as String? ?? '',
      publishTime: DateTime.parse(json['publishTime'] as String),
      isTop: json['isTop'] as bool? ?? false,
      privateLevel: json['privateLevel'] as int? ?? 0,
      targetDepts:
          (json['targetDepts'] as List<dynamic>?)
              ?.map((e) => e as String)
              .toList() ??
          [],
      targetUsers:
          (json['targetUsers'] as List<dynamic>?)
              ?.map((e) => e as String)
              .toList() ??
          [],
      requireConfirm: json['requireConfirm'] as bool? ?? false,
      expiryDate: DateTime.parse(json['expiryDate'] as String),
      attachments:
          (json['attachments'] as List<dynamic>?)
              ?.map((e) => e as String)
              .toList() ??
          [],
      readCount: json['readCount'] as int? ?? 0,
      unreadCount: json['unreadCount'] as int? ?? 0,
      createTime: DateTime.parse(json['createTime'] as String),
    );
  }
}
