// Version: 1.0.0 import '../services/database_helper.dart'; class Product { int? id; String productCode; String name; int price; // 単価(税込) int stock; String? category; String? unit; int isDeleted = 0; // Soft delete flag Product({ this.id, required this.productCode, required this.name, required this.price, this.stock = 0, this.category, this.unit, this.isDeleted = 0, }); Map toMap() { return { 'id': id, 'product_code': productCode, 'name': name, 'price': price, 'stock': stock, 'category': category ?? '', 'unit': unit ?? '', 'is_deleted': isDeleted, }; } factory Product.fromMap(Map map) { return Product( id: map['id'] as int?, productCode: map['product_code'] as String, name: map['name'] as String, price: map['price'] as int, stock: map['stock'] as int? ?? 0, category: map['category'] as String?, unit: map['unit'] as String?, isDeleted: map['is_deleted'] as int? ?? 0, ); } Product copyWith({ int? id, String? productCode, String? name, int? price, int? stock, String? category, String? unit, int? isDeleted, }) { return Product( id: id ?? this.id, productCode: productCode ?? this.productCode, name: name ?? this.name, price: price ?? this.price, stock: stock ?? this.stock, category: category ?? this.category, unit: unit ?? this.unit, isDeleted: isDeleted ?? this.isDeleted, ); } // 税込価格(引数にない場合は自身) int get taxPrice => price; }