feat: introduce TaxForm entity and adapter, refactor tax forms repository and use cases for improved data handling
This commit is contained in:
@@ -54,6 +54,7 @@ export 'src/entities/profile/staff_document.dart';
|
||||
export 'src/entities/profile/attire_item.dart';
|
||||
export 'src/entities/profile/relationship_type.dart';
|
||||
export 'src/entities/profile/industry.dart';
|
||||
export 'src/entities/profile/tax_form.dart';
|
||||
|
||||
// Ratings & Penalties
|
||||
export 'src/entities/ratings/staff_rating.dart';
|
||||
@@ -85,3 +86,4 @@ export 'src/adapters/profile/emergency_contact_adapter.dart';
|
||||
export 'src/adapters/profile/experience_adapter.dart';
|
||||
export 'src/entities/profile/experience_skill.dart';
|
||||
export 'src/adapters/profile/bank_account_adapter.dart';
|
||||
export 'src/adapters/profile/tax_form_adapter.dart';
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
import '../../entities/profile/tax_form.dart';
|
||||
|
||||
/// Adapter for [TaxForm] to map data layer values to domain entity.
|
||||
class TaxFormAdapter {
|
||||
/// Maps primitive values to [TaxForm].
|
||||
static TaxForm fromPrimitives({
|
||||
required String id,
|
||||
required String type,
|
||||
required String title,
|
||||
String? subtitle,
|
||||
String? description,
|
||||
required String status,
|
||||
String? staffId,
|
||||
dynamic formData,
|
||||
DateTime? createdAt,
|
||||
DateTime? updatedAt,
|
||||
}) {
|
||||
return TaxForm(
|
||||
id: id,
|
||||
type: _stringToType(type),
|
||||
title: title,
|
||||
subtitle: subtitle,
|
||||
description: description,
|
||||
status: _stringToStatus(status),
|
||||
staffId: staffId,
|
||||
formData: formData is Map ? Map<String, dynamic>.from(formData) : null,
|
||||
createdAt: createdAt,
|
||||
updatedAt: updatedAt,
|
||||
);
|
||||
}
|
||||
|
||||
static TaxFormType _stringToType(String? value) {
|
||||
if (value == null) return TaxFormType.i9;
|
||||
try {
|
||||
return TaxFormType.values.firstWhere(
|
||||
(TaxFormType e) => e.name.toLowerCase() == value.toLowerCase(),
|
||||
orElse: () => TaxFormType.i9,
|
||||
);
|
||||
} catch (_) {
|
||||
return TaxFormType.i9;
|
||||
}
|
||||
}
|
||||
|
||||
static TaxFormStatus _stringToStatus(String? value) {
|
||||
if (value == null) return TaxFormStatus.notStarted;
|
||||
try {
|
||||
final String normalizedValue = value.replaceAll('_', '').toLowerCase();
|
||||
// map DRAFT to inProgress
|
||||
if (normalizedValue == 'draft') return TaxFormStatus.inProgress;
|
||||
|
||||
return TaxFormStatus.values.firstWhere(
|
||||
(TaxFormStatus e) {
|
||||
// Handle differences like not_started vs notStarted if any,
|
||||
// but standardizing to lowercase is a good start.
|
||||
// The enum names are camelCase in Dart, but might be SNAKE_CASE from backend.
|
||||
final String normalizedEnum = e.name.toLowerCase();
|
||||
return normalizedValue == normalizedEnum;
|
||||
},
|
||||
orElse: () => TaxFormStatus.notStarted,
|
||||
);
|
||||
} catch (_) {
|
||||
return TaxFormStatus.notStarted;
|
||||
}
|
||||
}
|
||||
|
||||
/// Converts domain [TaxFormType] to string for backend.
|
||||
static String typeToString(TaxFormType type) {
|
||||
return type.name.toUpperCase();
|
||||
}
|
||||
|
||||
/// Converts domain [TaxFormStatus] to string for backend.
|
||||
static String statusToString(TaxFormStatus status) {
|
||||
switch (status) {
|
||||
case TaxFormStatus.notStarted:
|
||||
return 'NOT_STARTED';
|
||||
case TaxFormStatus.inProgress:
|
||||
return 'DRAFT';
|
||||
case TaxFormStatus.submitted:
|
||||
return 'SUBMITTED';
|
||||
case TaxFormStatus.approved:
|
||||
return 'APPROVED';
|
||||
case TaxFormStatus.rejected:
|
||||
return 'REJECTED';
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
|
||||
enum TaxFormType { i9, w4 }
|
||||
|
||||
enum TaxFormStatus { notStarted, inProgress, submitted, approved, rejected }
|
||||
|
||||
class TaxForm extends Equatable {
|
||||
final String id;
|
||||
final TaxFormType type;
|
||||
final String title;
|
||||
final String? subtitle;
|
||||
final String? description;
|
||||
final TaxFormStatus status;
|
||||
final String? staffId;
|
||||
final Map<String, dynamic>? formData;
|
||||
final DateTime? createdAt;
|
||||
final DateTime? updatedAt;
|
||||
|
||||
const TaxForm({
|
||||
required this.id,
|
||||
required this.type,
|
||||
required this.title,
|
||||
this.subtitle,
|
||||
this.description,
|
||||
this.status = TaxFormStatus.notStarted,
|
||||
this.staffId,
|
||||
this.formData,
|
||||
this.createdAt,
|
||||
this.updatedAt,
|
||||
});
|
||||
|
||||
@override
|
||||
List<Object?> get props => [
|
||||
id,
|
||||
type,
|
||||
title,
|
||||
subtitle,
|
||||
description,
|
||||
status,
|
||||
staffId,
|
||||
formData,
|
||||
createdAt,
|
||||
updatedAt,
|
||||
];
|
||||
}
|
||||
Reference in New Issue
Block a user