/// Domain Entity: Order
///
/// Represents a customer order (simplified to match API structure).
library;

import 'package:equatable/equatable.dart';

/// Order Entity
///
/// Pure domain entity matching API response structure
class Order extends Equatable {
  /// Order ID/Number
  final String name;

  /// Transaction date (ISO format string)
  final String transactionDate;

  /// Expected delivery date (ISO format string)
  final String deliveryDate;

  /// Delivery address
  final String address;

  /// Grand total amount
  final double grandTotal;

  /// Status label (Vietnamese)
  final String status;

  /// Status color (Warning, Success, Danger, Info, Secondary)
  final String statusColor;

  const Order({
    required this.name,
    required this.transactionDate,
    required this.deliveryDate,
    required this.address,
    required this.grandTotal,
    required this.status,
    required this.statusColor,
  });

  /// Get parsed transaction date
  DateTime? get transactionDateTime {
    try {
      return DateTime.parse(transactionDate);
    } catch (e) {
      return null;
    }
  }

  /// Get parsed delivery date
  DateTime? get deliveryDateTime {
    try {
      return DateTime.parse(deliveryDate);
    } catch (e) {
      return null;
    }
  }

  /// Copy with method for immutability
  Order copyWith({
    String? name,
    String? transactionDate,
    String? deliveryDate,
    String? address,
    double? grandTotal,
    String? status,
    String? statusColor,
  }) {
    return Order(
      name: name ?? this.name,
      transactionDate: transactionDate ?? this.transactionDate,
      deliveryDate: deliveryDate ?? this.deliveryDate,
      address: address ?? this.address,
      grandTotal: grandTotal ?? this.grandTotal,
      status: status ?? this.status,
      statusColor: statusColor ?? this.statusColor,
    );
  }

  @override
  List<Object?> get props => [
        name,
        transactionDate,
        deliveryDate,
        address,
        grandTotal,
        status,
        statusColor,
      ];

  @override
  String toString() {
    return 'Order(name: $name, status: $status, grandTotal: $grandTotal, transactionDate: $transactionDate)';
  }
}
