import 'package:niogu_app/core/enums/item_type.dart';
import 'package:niogu_app/core/enums/stock_card_type.dart';
import 'package:niogu_app/core/enums/stock_type.dart';

enum StockReportItemEmpty {
  loading,
  empty_database,
  empty_search_result,
  has_data,
}

class MovementTemp {
  final StockCardType type;
  final double initialStock;
  final double qty;
  final DateTime date;
  final StockType stockType;

  MovementTemp({
    required this.type,
    required this.initialStock,
    required this.qty,
    required this.date,
    required this.stockType,
  });
}

class StockReportItem {
  final String id;
  final ItemType itemType;
  final String name;
  final String? imageProduct;
  final String? variantName;
  final bool isUnlimited;
  final double initialStock;
  final double totalStockIn;
  final double totalStockOut;
  final double lastStock;
  final String unit;
  final bool isDeleteByOwner;
  final bool hasBeenDelete;

  const StockReportItem({
    required this.id,
    required this.itemType,
    required this.name,
    this.variantName,
    this.imageProduct,
    required this.isUnlimited,
    required this.initialStock,
    required this.totalStockIn,
    required this.totalStockOut,
    required this.lastStock,
    required this.unit,
    required this.isDeleteByOwner,
    required this.hasBeenDelete
  });

  StockReportItem copyWith({
    double? initialStock,
    double? totalStockIn,
    double? totalStockOut,
    double? lastStock,
  }) {
    return StockReportItem(
      id: id,
      itemType: itemType,
      name: name,
      variantName: this.variantName,
      imageProduct: imageProduct,
      isUnlimited: isUnlimited,
      initialStock: initialStock ?? this.initialStock,
      totalStockIn: totalStockIn ?? this.totalStockIn,
      totalStockOut: totalStockOut ?? this.totalStockOut,
      lastStock: lastStock ?? this.lastStock,
      unit: unit,
      isDeleteByOwner: isDeleteByOwner,
      hasBeenDelete: hasBeenDelete
    );
  }
}

class StockReportDetail {
  final String itemName;
  final String? variantName;
  final bool isUnlimited;
  final String outletName;
  final DateTime? startDate;
  final DateTime? endDate;
  final double initialStock;
  final double totalStockIn;
  final double totalStockOut;
  final double lastStock;
  final String unit;
  final List<StockMovement> movements;
  final DateTime createdAt;

  const StockReportDetail({
    required this.itemName,
    required this.variantName,
    required this.isUnlimited,
    required this.outletName,
    required this.startDate,
    required this.endDate,
    required this.initialStock,
    required this.totalStockIn,
    required this.totalStockOut,
    required this.lastStock,
    required this.unit,
    required this.movements,
    required this.createdAt,
  });

  StockReportDetail copyWith({
    double? totalStockIn,
    double? totalStockOut,
    double? lastStock,
  }) {
    return StockReportDetail(
      itemName: itemName,
      variantName: variantName,
      isUnlimited: isUnlimited,
      outletName: outletName,
      startDate: startDate,
      endDate: endDate,
      initialStock: initialStock,
      totalStockIn: totalStockIn ?? this.totalStockIn,
      totalStockOut: totalStockOut ?? this.totalStockOut,
      lastStock: lastStock ?? this.lastStock,
      unit: unit,
      movements: movements,
      createdAt: createdAt,
    );
  }
}

class StockMovement {
  final DateTime date;
  final String description;
  final String? notes;
  final String userName;
  final StockCardType type;
  final String? referenceId;
  final bool isStockIn;
  final bool isUnlimited;
  final bool modeChange;
  final String? beforeChange;
  final String? afterChange;
  final double stockIn;
  final double stockOut;
  final double remainingStock;

  const StockMovement({
    required this.date,
    required this.description,
    this.notes,
    required this.userName,
    required this.type,
    this.referenceId,
    required this.isStockIn,
    required this.isUnlimited,
    required this.modeChange,
    this.beforeChange,
    this.afterChange,
    required this.stockIn,
    required this.stockOut,
    required this.remainingStock,
  });
}
