import 'package:vital_local_database/core/interface/entity.dart';
import 'package:vital_local_database/core/sqlite/entity.dart';

import 'syncable.dart';

/// 病人实体
class PatientEntity extends SyncableEntity<PatientEntity> {
  static const String _tableName = "patients";
  static final _columns = PatientColumnsDefine();

  /**
   * 
   *     map['code'] = code;
    map['dataJson'] = dataJson;
    map['syncType'] = syncType.index;
    map['syncState'] = syncState.index;
   */

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

  @override
  PatientColumnsDefine get columns => _columns;

  @override
  String get tableName => _tableName;

  /// 扩展Json
  String? extJson;

  /// 姓名
  String name = "";

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

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

/// 病人字段定义
class PatientColumnsDefine extends SyncableColumnsDefine<PatientEntity>
    implements IDbColumnsDefine<PatientEntity> {
  final name = DbColumn<String>("name");
  final extJson = DbColumn<String>("extJson");
}
