import 'package:hive/hive.dart';

part 'product_model.g.dart';

@HiveType(typeId: 2)
class ProductModel extends HiveObject {
  @HiveField(0)
  final String id;

  @HiveField(1)
  final String userId;

  @HiveField(2)
  final String name;

  @HiveField(3)
  final String category; // 'pastas', 'bebidas', 'acessorios', 'outros'

  @HiveField(4)
  final int quantity;

  @HiveField(5)
  final double purchasePrice;

  @HiveField(6)
  final double salePrice;

  @HiveField(7)
  final int minStock;
  @HiveField(8)
  final String? imagePath;

  ProductModel({
    required this.id,
    required this.userId,
    required this.name,
    required this.category,
    required this.quantity,
    required this.purchasePrice,
    required this.salePrice,
    required this.minStock,
    this.imagePath,
  });

  bool get isLowStock => quantity <= minStock;

  ProductModel copyWith({
    String? id,
    String? userId,
    String? name,
    String? category,
    int? quantity,
    double? purchasePrice,
    double? salePrice,
    int? minStock,
    String? imagePath,
  }) {
    return ProductModel(
      id: id ?? this.id,
      userId: userId ?? this.userId,
      name: name ?? this.name,
      category: category ?? this.category,
      quantity: quantity ?? this.quantity,
      purchasePrice: purchasePrice ?? this.purchasePrice,
      salePrice: salePrice ?? this.salePrice,
      minStock: minStock ?? this.minStock,
      imagePath: imagePath ?? this.imagePath,
    );
  }
}

class ProductCategories {
  static const String pastes = 'pastas';
  static const String beverages = 'bebidas';
  static const String accessories = 'acessorios';
  static const String other = 'outros';

  static List<String> get all => [pastes, beverages, accessories, other];

  static String getDisplayName(String category) {
    switch (category) {
      case pastes:
        return 'Pastas e Pomadas';
      case beverages:
        return 'Bebidas (Frigobar)';
      case accessories:
        return 'Acessórios';
      case other:
        return 'Outros';
      default:
        return category;
    }
  }
}
