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

enum ProductEmpty { loading, empty_database, empty_search_result, has_data }

class Product {
  final String id;
  final String name;
  final List<String>? productImages;
  final bool hasVariant;
  final int variantCount;
  final int newVariantCount;
  final String stockType;
  final String remainingStock;
  final String displaySellingPrice;

  const Product({
    required this.id,
    required this.name,
    required this.productImages,
    required this.hasVariant,
    required this.variantCount,
    required this.newVariantCount,
    required this.stockType,
    required this.remainingStock,
    required this.displaySellingPrice,
  });
}

class UpsertProduct {
  final String localId;
  final String categoryId;
  final String unitId;
  final String name;
  final List<String>? localImagePath;
  final double averageRating;
  final int ratingCount;
  final bool hasVariant;
  final SyncStatus syncStatus;

  UpsertProduct({
    String? localId,
    required this.categoryId,
    required this.unitId,
    required this.name,
    this.localImagePath,
    this.averageRating = 0.0,
    this.ratingCount = 0,
    required this.hasVariant,
    this.syncStatus = SyncStatus.dirty,
  }) : localId = localId ?? const Uuid().v7().toString();
}

class UpsertProductVariant {
  final String localId;
  final String productId;
  final String? outletInventoryId;
  final String name;
  final String? localImagePath;
  final double? stock;
  final double? costPrice;
  final double? sellingPrice;
  final bool isProductVariant;
  final SyncStatus syncStatus;

  UpsertProductVariant({
    String? localId,
    required this.productId,
    this.outletInventoryId,
    required this.name,
    this.localImagePath,
    this.stock,
    this.costPrice,
    this.sellingPrice,
    this.isProductVariant = false,
    this.syncStatus = SyncStatus.dirty,
  }) : localId = localId ?? const Uuid().v7().toString();
}

class ProductWithVariant {
  final String? productVariantId;
  final String? outletInventoryId;
  final String? imagePath;
  final String name;
  final double stock;
  final double costPrice;
  final double sellingPrice;

  const ProductWithVariant({
    this.productVariantId,
    this.outletInventoryId,
    this.imagePath,
    required this.name,
    this.stock = 0.0,
    required this.costPrice,
    required this.sellingPrice,
  });
}

class ProductDetail {
  final String localId;
  final List<String>? productImages;
  final String name;
  final String categoryId;
  final bool hasVariant;
  final List<ProductVariantDetail> variants;
  final String unitId;

  const ProductDetail({
    required this.localId,
    this.productImages,
    required this.name,
    required this.categoryId,
    required this.hasVariant,
    required this.variants,
    required this.unitId,
  });
}

class ProductVariantDetail {
  final String productVariantId;
  final String outletInventoryId;
  final String? image;
  final String name;
  final double costPrice;
  final double sellingPrice;
  final StockType stockType;
  final double stock;

  const ProductVariantDetail({
    required this.productVariantId,
    required this.outletInventoryId,
    this.image,
    required this.name,
    required this.costPrice,
    required this.sellingPrice,
    required this.stockType,
    required this.stock,
  });
}

class DeleteProductVariant {
  final String productId;
  final String productVariantId;
  final String outletInventoryId;

  const DeleteProductVariant({
    required this.productId,
    required this.productVariantId,
    required this.outletInventoryId,
  });
}

class DeleteProductSnapshot {
  final String productId;
  final String? imagePath;
  final String name;
  final double totalSold;
  final String currentOutletName;
  final bool isMainOutlet;
  final int totalOutletCount;

  DeleteProductSnapshot({
    required this.productId,
    this.imagePath,
    required this.name,
    required this.totalSold,
    required this.currentOutletName,
    required this.isMainOutlet,
    required this.totalOutletCount,
  });
}

class DeleteProduct {
  final String productVariantId;
  final String outletInventoryId;

  DeleteProduct({
    required this.productVariantId,
    required this.outletInventoryId,
  });
}

class UpdateStockProduct {
  final String outletInventoryId;
  final String productVariantId;
  final StockType stockType;
  final double stock;
  final double quantity;

  const UpdateStockProduct({
    required this.outletInventoryId,
    required this.productVariantId,
    required this.stockType,
    required this.stock,
    required this.quantity,
  });
}

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

class ProductChoice {
  final String id;
  final String? imagePath;
  final String name;
  final bool hasVariant;

  const ProductChoice({
    required this.id,
    this.imagePath,
    required this.name,
    required this.hasVariant,
  });
}

class NewVariant {
  final String id;
  final int amount;

  const NewVariant({required this.id, required this.amount});
}
