course_module_entity.dart 1.92 KB
import 'dart:convert';

import 'package:wow_english/generated/json/base/json_field.dart';
import 'package:wow_english/generated/json/course_module_entity.g.dart';

@JsonSerializable()
class CourseModuleEntity {
  int? id;
  String? code;
  int? courseModuleThemeId;
  int? courseTotal;
  String? coverUrl;
  String? createTime;
  String? deleted;
  String? des;
  String? modifyTime;
  String? name;
  int? opening;
  String? picUrl;
  int? sortOrder;
  int? status;
  String? courseModuleThemeColor;

  // 无参构造函数
  CourseModuleEntity.empty();

  // 命名构造函数
  CourseModuleEntity({
    this.id,
    this.code,
    this.courseModuleThemeId,
    this.courseTotal,
    this.coverUrl,
    this.createTime,
    this.deleted,
    this.des,
    this.modifyTime,
    this.name,
    this.opening,
    this.picUrl,
    this.sortOrder,
    this.status,
    this.courseModuleThemeColor,
  });

  factory CourseModuleEntity.fromJson(Map<String, dynamic> json) =>
      $CourseModuleEntityFromJson(json);

  Map<String, dynamic> toJson() => $CourseModuleEntityToJson(this);

  // Factory constructor for creating an instance with only three parameters
  factory CourseModuleEntity.of(int? courseModuleId, String? courseModuleCode,
      String? courseModuleName, String? courseModuleThemeColor) {
    return CourseModuleEntity(
      id: courseModuleId,
      code: courseModuleCode,
      name: courseModuleName,
      courseModuleThemeColor: courseModuleThemeColor,
      // Set default values or leave other fields null
    );
  }

  @override
  String toString() {
    return jsonEncode(this);
  }
}

///对可空的CourseModuleEntity对象扩展
extension PersonSafeExt on CourseModuleEntity? {
  ///获取非空的主题色,系统主题色0xFF00B6F1兜底
  String getSafeThemeColor() {
    return this?.courseModuleThemeColor ?? '0xFFFFFFFF';
  }

  ///获取非空的阶段名称
  String getSafeName() {
    return this?.name ?? 'learn wow!';
  }
}