price policy
This commit is contained in:
@@ -4,44 +4,47 @@
|
||||
/// This entity is framework-independent and contains only business logic.
|
||||
library;
|
||||
|
||||
/// Price policy document entity
|
||||
class PriceDocument {
|
||||
/// Unique document ID
|
||||
final String id;
|
||||
import 'package:equatable/equatable.dart';
|
||||
|
||||
/// Price policy document entity
|
||||
class PriceDocument extends Equatable {
|
||||
/// Document title
|
||||
final String title;
|
||||
|
||||
/// Document description
|
||||
final String description;
|
||||
/// URL to download the document
|
||||
final String fileUrl;
|
||||
|
||||
/// Date the document was published
|
||||
final DateTime publishedDate;
|
||||
|
||||
/// Type of document (PDF or Excel)
|
||||
final DocumentType documentType;
|
||||
/// Date the document was last updated
|
||||
final DateTime updatedAt;
|
||||
|
||||
/// Category (policy or price list)
|
||||
final DocumentCategory category;
|
||||
|
||||
/// URL to download the document
|
||||
final String downloadUrl;
|
||||
|
||||
/// Optional file size display string
|
||||
final String? fileSize;
|
||||
/// Local file path after download (in-memory cache for current session)
|
||||
final String? filePath;
|
||||
|
||||
/// Constructor
|
||||
const PriceDocument({
|
||||
required this.id,
|
||||
required this.title,
|
||||
required this.description,
|
||||
required this.publishedDate,
|
||||
required this.documentType,
|
||||
required this.fileUrl,
|
||||
required this.updatedAt,
|
||||
required this.category,
|
||||
required this.downloadUrl,
|
||||
this.fileSize,
|
||||
this.filePath,
|
||||
});
|
||||
|
||||
/// Get document type based on file extension
|
||||
DocumentType get documentType {
|
||||
final lowerUrl = fileUrl.toLowerCase();
|
||||
if (lowerUrl.endsWith('.pdf')) {
|
||||
return DocumentType.pdf;
|
||||
} else if (lowerUrl.endsWith('.xlsx') ||
|
||||
lowerUrl.endsWith('.xls') ||
|
||||
lowerUrl.endsWith('.csv')) {
|
||||
return DocumentType.excel;
|
||||
}
|
||||
return DocumentType.excel; // Default to excel
|
||||
}
|
||||
|
||||
/// Check if document is a PDF
|
||||
bool get isPdf => documentType == DocumentType.pdf;
|
||||
|
||||
@@ -56,9 +59,15 @@ class PriceDocument {
|
||||
|
||||
/// Get formatted published date (dd/MM/yyyy)
|
||||
String get formattedDate {
|
||||
return '${publishedDate.day.toString().padLeft(2, '0')}/'
|
||||
'${publishedDate.month.toString().padLeft(2, '0')}/'
|
||||
'${publishedDate.year}';
|
||||
return '${updatedAt.day.toString().padLeft(2, '0')}/'
|
||||
'${updatedAt.month.toString().padLeft(2, '0')}/'
|
||||
'${updatedAt.year}';
|
||||
}
|
||||
|
||||
/// Get formatted date with time (dd/MM/yyyy HH:mm)
|
||||
String get formattedDateTime {
|
||||
return '$formattedDate ${updatedAt.hour.toString().padLeft(2, '0')}:'
|
||||
'${updatedAt.minute.toString().padLeft(2, '0')}';
|
||||
}
|
||||
|
||||
/// Get formatted date with prefix based on category
|
||||
@@ -72,64 +81,30 @@ class PriceDocument {
|
||||
|
||||
/// Copy with method for immutability
|
||||
PriceDocument copyWith({
|
||||
String? id,
|
||||
String? title,
|
||||
String? description,
|
||||
DateTime? publishedDate,
|
||||
DocumentType? documentType,
|
||||
String? fileUrl,
|
||||
DateTime? updatedAt,
|
||||
DocumentCategory? category,
|
||||
String? downloadUrl,
|
||||
String? fileSize,
|
||||
String? filePath,
|
||||
}) {
|
||||
return PriceDocument(
|
||||
id: id ?? this.id,
|
||||
title: title ?? this.title,
|
||||
description: description ?? this.description,
|
||||
publishedDate: publishedDate ?? this.publishedDate,
|
||||
documentType: documentType ?? this.documentType,
|
||||
fileUrl: fileUrl ?? this.fileUrl,
|
||||
updatedAt: updatedAt ?? this.updatedAt,
|
||||
category: category ?? this.category,
|
||||
downloadUrl: downloadUrl ?? this.downloadUrl,
|
||||
fileSize: fileSize ?? this.fileSize,
|
||||
filePath: filePath ?? this.filePath,
|
||||
);
|
||||
}
|
||||
|
||||
/// Equality operator
|
||||
/// Equatable props for equality comparison
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
if (identical(this, other)) return true;
|
||||
|
||||
return other is PriceDocument &&
|
||||
other.id == id &&
|
||||
other.title == title &&
|
||||
other.description == description &&
|
||||
other.publishedDate == publishedDate &&
|
||||
other.documentType == documentType &&
|
||||
other.category == category &&
|
||||
other.downloadUrl == downloadUrl &&
|
||||
other.fileSize == fileSize;
|
||||
}
|
||||
|
||||
/// Hash code
|
||||
@override
|
||||
int get hashCode {
|
||||
return Object.hash(
|
||||
id,
|
||||
title,
|
||||
description,
|
||||
publishedDate,
|
||||
documentType,
|
||||
category,
|
||||
downloadUrl,
|
||||
fileSize,
|
||||
);
|
||||
}
|
||||
List<Object?> get props => [title, fileUrl, updatedAt, category, filePath];
|
||||
|
||||
/// String representation
|
||||
@override
|
||||
String toString() {
|
||||
return 'PriceDocument(id: $id, title: $title, description: $description, '
|
||||
'publishedDate: $publishedDate, documentType: $documentType, '
|
||||
'category: $category, downloadUrl: $downloadUrl, fileSize: $fileSize)';
|
||||
return 'PriceDocument(title: $title, fileUrl: $fileUrl, '
|
||||
'updatedAt: $updatedAt, category: $category, filePath: $filePath)';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -138,8 +113,8 @@ enum DocumentType { pdf, excel }
|
||||
|
||||
/// Document category enum
|
||||
enum DocumentCategory {
|
||||
policy, // Chính sách giá
|
||||
priceList, // Bảng giá
|
||||
policy, // Chính sách giá (PRICING_RULE)
|
||||
priceList, // Bảng giá (PRICE_LIST)
|
||||
}
|
||||
|
||||
// Extension for display
|
||||
@@ -163,4 +138,14 @@ extension DocumentCategoryX on DocumentCategory {
|
||||
return 'Bảng giá';
|
||||
}
|
||||
}
|
||||
|
||||
/// Get API parameter value for this category
|
||||
String get apiValue {
|
||||
switch (this) {
|
||||
case DocumentCategory.policy:
|
||||
return 'PRICING_RULE';
|
||||
case DocumentCategory.priceList:
|
||||
return 'PRICE_LIST';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user