add start/business unit
This commit is contained in:
91
lib/features/auth/data/models/business_unit_model.dart
Normal file
91
lib/features/auth/data/models/business_unit_model.dart
Normal file
@@ -0,0 +1,91 @@
|
||||
/// Business Unit Data Model
|
||||
///
|
||||
/// Hive model for local storage of business units.
|
||||
library;
|
||||
|
||||
import 'package:hive_ce/hive.dart';
|
||||
import 'package:worker/core/constants/storage_constants.dart';
|
||||
import 'package:worker/features/auth/domain/entities/business_unit.dart';
|
||||
|
||||
part 'business_unit_model.g.dart';
|
||||
|
||||
/// Business Unit Model for Hive storage
|
||||
@HiveType(typeId: HiveTypeIds.businessUnitModel)
|
||||
class BusinessUnitModel extends HiveObject {
|
||||
/// Unique business unit identifier
|
||||
@HiveField(0)
|
||||
String id;
|
||||
|
||||
/// Business unit code (e.g., "VIKD", "HSKD", "LPKD")
|
||||
@HiveField(1)
|
||||
String code;
|
||||
|
||||
/// Display name
|
||||
@HiveField(2)
|
||||
String name;
|
||||
|
||||
/// Description
|
||||
@HiveField(3)
|
||||
String? description;
|
||||
|
||||
/// Whether this is the default unit
|
||||
@HiveField(4)
|
||||
bool isDefault;
|
||||
|
||||
BusinessUnitModel({
|
||||
required this.id,
|
||||
required this.code,
|
||||
required this.name,
|
||||
this.description,
|
||||
this.isDefault = false,
|
||||
});
|
||||
|
||||
/// Convert to domain entity
|
||||
BusinessUnit toEntity() {
|
||||
return BusinessUnit(
|
||||
id: id,
|
||||
code: code,
|
||||
name: name,
|
||||
description: description,
|
||||
isDefault: isDefault,
|
||||
);
|
||||
}
|
||||
|
||||
/// Create from domain entity
|
||||
factory BusinessUnitModel.fromEntity(BusinessUnit entity) {
|
||||
return BusinessUnitModel(
|
||||
id: entity.id,
|
||||
code: entity.code,
|
||||
name: entity.name,
|
||||
description: entity.description,
|
||||
isDefault: entity.isDefault,
|
||||
);
|
||||
}
|
||||
|
||||
/// Create from JSON
|
||||
factory BusinessUnitModel.fromJson(Map<String, dynamic> json) {
|
||||
return BusinessUnitModel(
|
||||
id: json['id'] as String,
|
||||
code: json['code'] as String,
|
||||
name: json['name'] as String,
|
||||
description: json['description'] as String?,
|
||||
isDefault: json['is_default'] as bool? ?? false,
|
||||
);
|
||||
}
|
||||
|
||||
/// Convert to JSON
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'id': id,
|
||||
'code': code,
|
||||
'name': name,
|
||||
'description': description,
|
||||
'is_default': isDefault,
|
||||
};
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'BusinessUnitModel(id: $id, code: $code, name: $name)';
|
||||
}
|
||||
}
|
||||
53
lib/features/auth/data/models/business_unit_model.g.dart
Normal file
53
lib/features/auth/data/models/business_unit_model.g.dart
Normal file
@@ -0,0 +1,53 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'business_unit_model.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// TypeAdapterGenerator
|
||||
// **************************************************************************
|
||||
|
||||
class BusinessUnitModelAdapter extends TypeAdapter<BusinessUnitModel> {
|
||||
@override
|
||||
final typeId = 29;
|
||||
|
||||
@override
|
||||
BusinessUnitModel read(BinaryReader reader) {
|
||||
final numOfFields = reader.readByte();
|
||||
final fields = <int, dynamic>{
|
||||
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
|
||||
};
|
||||
return BusinessUnitModel(
|
||||
id: fields[0] as String,
|
||||
code: fields[1] as String,
|
||||
name: fields[2] as String,
|
||||
description: fields[3] as String?,
|
||||
isDefault: fields[4] == null ? false : fields[4] as bool,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void write(BinaryWriter writer, BusinessUnitModel obj) {
|
||||
writer
|
||||
..writeByte(5)
|
||||
..writeByte(0)
|
||||
..write(obj.id)
|
||||
..writeByte(1)
|
||||
..write(obj.code)
|
||||
..writeByte(2)
|
||||
..write(obj.name)
|
||||
..writeByte(3)
|
||||
..write(obj.description)
|
||||
..writeByte(4)
|
||||
..write(obj.isDefault);
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => typeId.hashCode;
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
identical(this, other) ||
|
||||
other is BusinessUnitModelAdapter &&
|
||||
runtimeType == other.runtimeType &&
|
||||
typeId == other.typeId;
|
||||
}
|
||||
Reference in New Issue
Block a user