import 'package:vital_local_database/core/interface/entity.dart';
import 'package:vital_local_database/core/sqlite/entity.dart';
import 'package:vitalapp/database/entities/syncable.dart';

/// 检测记录表实体
class DiagnosisEntity extends SyncableEntity<DiagnosisEntity> {
  static const String _tableName = "diagnosis";
  static final _columns = DiagnosisColumnsDefine();

  // ignore: constant_identifier_names
  static const TABLE_CREATE_SQL = 'CREATE TABLE IF NOT EXISTS "diagnosis" ('
      '"id" INTEGER NOT NULL,'
      '"code" VARCHAR(100) NOT NULL,'
      '"patientCode" VARCHAR(100) NOT NULL,'
      '"dataJson" TEXT NOT NULL,'
      '"syncType" INTEGER NOT NULL,'
      '"syncState" INTEGER NOT NULL,'
      '"createTime" DATETIME NOT NULL,'
      '"updateTime" DATETIME NULL,'
      '"isValid" INTEGER NOT NULL,'
      'PRIMARY KEY ("id")'
      ');';

  @override
  DiagnosisColumnsDefine get columns => _columns;

  @override
  String get tableName => _tableName;

  /// 居民Code
  String patientCode = "";

  @override
  Map<String, dynamic> toJson() {
    final map = super.toJson();
    map['patientCode'] = patientCode;
    return map;
  }

  @override
  DiagnosisEntity fromJson(Map<String, dynamic> map) {
    super.fromJson(map);
    patientCode = map['patientCode'];
    return this;
  }
}

/// 检测记录字段定义
class DiagnosisColumnsDefine extends SyncableColumnsDefine<DiagnosisEntity>
    implements IDbColumnsDefine<DiagnosisEntity> {
  final patientCode = DbColumn<String>("patientCode");
}
