import 'package:niogu_app/core/enums/sync_status.dart';
import 'package:uuid/uuid.dart';

enum RawMaterialEmpty { loading, empty_database, empty_search_result, has_data }

class RawMaterial {
  final String id;
  final String name;
  final String remainingStock;
  final String displayPurchasePrice;
  final int countProductUsage;

  const RawMaterial({
    required this.id,
    required this.name,
    required this.remainingStock,
    required this.displayPurchasePrice,
    required this.countProductUsage,
  });

  RawMaterial copyWith({int? countProductUsage}) {
    return RawMaterial(
      id: id,
      name: name,
      remainingStock: remainingStock,
      displayPurchasePrice: displayPurchasePrice,
      countProductUsage: countProductUsage ?? this.countProductUsage,
    );
  }
}

class RawMaterialDetail {
  final String id;
  final String name;
  final double purchasePrice;
  final double stock;
  final String unitId;
  final String outletInventoryId;
  final List<SelectedProductUsageMaterial> productUsages;

  const RawMaterialDetail({
    required this.id,
    required this.name,
    required this.purchasePrice,
    required this.stock,
    required this.unitId,
    required this.outletInventoryId,
    required this.productUsages,
  });
}

class UpsertRawMaterial {
  final String localId;
  final String unitId;
  final String name;
  final SyncStatus syncStatus;

  UpsertRawMaterial({
    String? localId,
    required this.unitId,
    required this.name,
    this.syncStatus = SyncStatus.dirty,
  }) : localId = localId ?? Uuid().v7().toString();
}

class UpsertReceiptItem {
  final String localId;
  final String productUsageId;
  final String rawMaterialId;
  final double quantity;
  final SyncStatus syncStatus;

  UpsertReceiptItem({
    String? localId,
    required this.productUsageId,
    required this.rawMaterialId,
    required this.quantity,
    this.syncStatus = SyncStatus.dirty,
  }) : localId = localId ?? Uuid().v7().toString();
}

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

class ProductUsageMaterial {
  final String id;
  final String name;
  final String? imagePath;
  final bool hasVariant;
  final List<VariantUsageMaterial> variants;
  final bool hasBeenDelete;

  const ProductUsageMaterial({
    required this.id,
    required this.name,
    this.imagePath,
    this.hasVariant = false,
    required this.variants,
    required this.hasBeenDelete,
  });
}

class VariantUsageMaterial {
  final String id;
  final String name;
  final bool isProductVariant;
  final bool hasBeenDelete;

  const VariantUsageMaterial({
    required this.id,
    required this.name,
    required this.isProductVariant,
    required this.hasBeenDelete,
  });
}

class SelectedProductUsageMaterial {
  final String? receiptItemId;
  final String productUsageId;
  final double quantity;

  const SelectedProductUsageMaterial({
    this.receiptItemId,
    required this.productUsageId,
    required this.quantity,
  });

  SelectedProductUsageMaterial copyWith({double? quantity}) {
    return SelectedProductUsageMaterial(
      receiptItemId: receiptItemId,
      productUsageId: productUsageId,
      quantity: quantity ?? this.quantity,
    );
  }
}

class DeleteProductUsageMaterial {
  final String rawMaterialId;
  final String productUsageId;

  const DeleteProductUsageMaterial({
    required this.rawMaterialId,
    required this.productUsageId,
  });
}

class DeleteRawMaterialSnapshot {
  final String rawMaterialId;
  final String name;
  final int totalProductUsage;
  final String currentOutletName;
  final bool isMainOutlet;
  final int totalOutletCount;

  const DeleteRawMaterialSnapshot({
    required this.rawMaterialId,
    required this.name,
    required this.totalProductUsage,
    required this.currentOutletName,
    required this.isMainOutlet,
    required this.totalOutletCount,
  });
}

class DeleteRawMaterial {
  final String rawMaterialId;
  final String outletInventoryId;
  final String receiptItemId;

  const DeleteRawMaterial({
    required this.rawMaterialId,
    required this.outletInventoryId,
    required this.receiptItemId,
  });
}

class UpdateStockRawMaterial {
  final String outletInventoryId;
  final String productVariantId;
  final String rawMaterialId;
  final String name;
  final String unit;
  final double productQuantity;
  final double quantity;
  final double stock;
  final double purchasePrice;

  const UpdateStockRawMaterial({
    this.outletInventoryId = '',
    required this.productVariantId,
    required this.rawMaterialId,
    required this.name,
    required this.unit,
    required this.productQuantity,
    required this.quantity,
    this.stock = 0.0,
    this.purchasePrice = 0.0,
  });

  UpdateStockRawMaterial copyWith({
    String? outletInventoryId,
    double? stock,
    double? purchasePrice,
  }) {
    return UpdateStockRawMaterial(
      outletInventoryId: outletInventoryId ?? this.outletInventoryId,
      productVariantId: productVariantId,
      rawMaterialId: rawMaterialId,
      name: name,
      unit: unit,
      productQuantity: productQuantity,
      quantity: quantity,
      stock: stock ?? this.stock,
      purchasePrice: purchasePrice ?? this.purchasePrice,
    );
  }
}

enum RawMaterialChoiceEmpty { loading, empty_database, empty_search_result, has_data }


class RawMaterialChoice {
  final String id;
  final String name;
  final int countProductUsage;

  const RawMaterialChoice({
    required this.id,
    required this.name,
    required this.countProductUsage
  });
}
