apskel-pos-flutter/lib/data/models/response/customer_response_model.dart

128 lines
3.1 KiB
Dart
Raw Normal View History

2025-08-03 15:28:27 +07:00
import 'dart:convert';
class CustomerResponseModel {
final bool? success;
final CustomerData? data;
final dynamic errors;
CustomerResponseModel({
this.success,
this.data,
this.errors,
});
factory CustomerResponseModel.fromJson(String str) =>
CustomerResponseModel.fromMap(json.decode(str));
String toJson() => json.encode(toMap());
factory CustomerResponseModel.fromMap(Map<String, dynamic> json) =>
CustomerResponseModel(
success: json["success"],
data: json["data"] == null ? null : CustomerData.fromMap(json["data"]),
errors: json["errors"],
);
Map<String, dynamic> toMap() => {
"success": success,
"data": data?.toMap(),
"errors": errors,
};
}
class CustomerData {
final List<Customer>? customers;
final int? totalCount;
final int? page;
final int? limit;
final int? totalPages;
CustomerData({
this.customers,
this.totalCount,
this.page,
this.limit,
this.totalPages,
});
factory CustomerData.fromMap(Map<String, dynamic> json) => CustomerData(
customers: json["data"] == null
? []
: List<Customer>.from(json["data"].map((x) => Customer.fromMap(x))),
totalCount: json["total_count"],
page: json["page"],
limit: json["limit"],
totalPages: json["total_pages"],
);
Map<String, dynamic> toMap() => {
"data": customers == null
? []
: List<dynamic>.from(customers!.map((x) => x.toMap())),
"total_count": totalCount,
"page": page,
"limit": limit,
"total_pages": totalPages,
};
}
class Customer {
final String? id;
final String? organizationId;
final String? name;
2025-08-03 16:16:41 +07:00
final String? email;
final String? phone;
final String? address;
2025-08-03 15:28:27 +07:00
final bool? isDefault;
final bool? isActive;
final Map<String, dynamic>? metadata;
final DateTime? createdAt;
final DateTime? updatedAt;
Customer({
this.id,
this.organizationId,
this.name,
2025-08-03 16:16:41 +07:00
this.email,
this.phone,
this.address,
2025-08-03 15:28:27 +07:00
this.isDefault,
this.isActive,
this.metadata,
this.createdAt,
this.updatedAt,
});
factory Customer.fromMap(Map<String, dynamic> json) => Customer(
id: json["id"],
organizationId: json["organization_id"],
name: json["name"],
2025-08-03 16:16:41 +07:00
email: json["email"],
phone: json["phone"],
address: json["address"],
2025-08-03 15:28:27 +07:00
isDefault: json["is_default"],
isActive: json["is_active"],
metadata: json["metadata"] ?? {},
createdAt: json["created_at"] == null
? null
: DateTime.parse(json["created_at"]),
updatedAt: json["updated_at"] == null
? null
: DateTime.parse(json["updated_at"]),
);
Map<String, dynamic> toMap() => {
"id": id,
"organization_id": organizationId,
"name": name,
2025-08-03 16:16:41 +07:00
"email": email,
"phone": phone,
"address": address,
2025-08-03 15:28:27 +07:00
"is_default": isDefault,
"is_active": isActive,
"metadata": metadata,
"created_at": createdAt?.toIso8601String(),
"updated_at": updatedAt?.toIso8601String(),
};
}