163 lines
4.0 KiB
Dart
Raw Normal View History

2025-08-03 12:56:13 +07:00
import 'dart:convert';
2025-08-07 22:03:05 +07:00
import 'package:enaklo_pos/data/type/bussines_type.dart';
2025-08-03 12:56:13 +07:00
class OutletResponse {
final bool? success;
final OutletData? data;
final dynamic errors;
OutletResponse({
this.success,
this.data,
this.errors,
});
factory OutletResponse.fromJson(String str) =>
OutletResponse.fromMap(json.decode(str));
String toJson() => json.encode(toMap());
factory OutletResponse.fromMap(Map<String, dynamic> json) => OutletResponse(
success: json["success"],
data: json["data"] == null ? null : OutletData.fromMap(json["data"]),
errors: json["errors"],
);
Map<String, dynamic> toMap() => {
"success": success,
"data": data?.toMap(),
"errors": errors,
};
}
2025-08-04 13:15:03 +07:00
class OutletDetailResponse {
final bool? success;
final Outlet? data;
final dynamic errors;
OutletDetailResponse({
this.success,
this.data,
this.errors,
});
factory OutletDetailResponse.fromJson(String str) =>
OutletDetailResponse.fromMap(json.decode(str));
String toJson() => json.encode(toMap());
factory OutletDetailResponse.fromMap(Map<String, dynamic> json) =>
OutletDetailResponse(
success: json["success"],
data: json["data"] == null ? null : Outlet.fromMap(json["data"]),
errors: json["errors"],
);
Map<String, dynamic> toMap() => {
"success": success,
"data": data?.toMap(),
"errors": errors,
};
}
2025-08-03 12:56:13 +07:00
class OutletData {
final List<Outlet>? outlets;
final int? totalCount;
final int? page;
final int? limit;
final int? totalPages;
OutletData({
this.outlets,
this.totalCount,
this.page,
this.limit,
this.totalPages,
});
factory OutletData.fromMap(Map<String, dynamic> json) => OutletData(
outlets: json["outlets"] == null
? []
: List<Outlet>.from(json["outlets"].map((x) => Outlet.fromMap(x))),
totalCount: json["total_count"],
page: json["page"],
limit: json["limit"],
totalPages: json["total_pages"],
);
Map<String, dynamic> toMap() => {
"outlets": outlets == null
? []
: List<dynamic>.from(outlets!.map((x) => x.toMap())),
"total_count": totalCount,
"page": page,
"limit": limit,
"total_pages": totalPages,
};
}
class Outlet {
final String? id;
final String? organizationId;
final String? name;
final String? address;
final String? phoneNumber;
2025-08-07 22:03:05 +07:00
final BusinessType? businessType;
2025-08-03 12:56:13 +07:00
final String? currency;
final int? taxRate;
final bool? isActive;
final DateTime? createdAt;
final DateTime? updatedAt;
Outlet({
this.id,
this.organizationId,
this.name,
this.address,
this.phoneNumber,
this.businessType,
this.currency,
this.taxRate,
this.isActive,
this.createdAt,
this.updatedAt,
});
factory Outlet.fromMap(Map<String, dynamic> json) => Outlet(
id: json["id"],
organizationId: json["organization_id"],
name: json["name"],
address: json["address"],
phoneNumber: json["phone_number"],
2025-08-07 22:03:05 +07:00
businessType: BusinessType.fromString(json["business_type"]),
2025-08-03 12:56:13 +07:00
currency: json["currency"],
taxRate: json["tax_rate"],
isActive: json["is_active"],
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,
"address": address,
"phone_number": phoneNumber,
2025-08-07 22:03:05 +07:00
"business_type": businessType?.value,
2025-08-03 12:56:13 +07:00
"currency": currency,
"tax_rate": taxRate,
"is_active": isActive,
"created_at": createdAt?.toIso8601String(),
"updated_at": updatedAt?.toIso8601String(),
};
factory Outlet.fromJson(String str) => Outlet.fromMap(json.decode(str));
String toJson() => json.encode(toMap());
}