/// 제품(Product) 도메인 엔티티.
class Product {
  Product({
    this.id,
    required this.productCode,
    required this.productName,
    this.vendor,
    this.uom,
    this.isActive = true,
    this.isDeleted = false,
    this.note,
    this.createdAt,
    this.updatedAt,
  });

  final int? id;
  final String productCode;
  final String productName;
  final ProductVendor? vendor;
  final ProductUom? uom;
  final bool isActive;
  final bool isDeleted;
  final String? note;
  final DateTime? createdAt;
  final DateTime? updatedAt;

  /// 일부 속성을 변경한 새 인스턴스를 반환한다.
  Product copyWith({
    int? id,
    String? productCode,
    String? productName,
    ProductVendor? vendor,
    ProductUom? uom,
    bool? isActive,
    bool? isDeleted,
    String? note,
    DateTime? createdAt,
    DateTime? updatedAt,
  }) {
    return Product(
      id: id ?? this.id,
      productCode: productCode ?? this.productCode,
      productName: productName ?? this.productName,
      vendor: vendor ?? this.vendor,
      uom: uom ?? this.uom,
      isActive: isActive ?? this.isActive,
      isDeleted: isDeleted ?? this.isDeleted,
      note: note ?? this.note,
      createdAt: createdAt ?? this.createdAt,
      updatedAt: updatedAt ?? this.updatedAt,
    );
  }
}

/// 제품에 연결된 공급업체 정보.
class ProductVendor {
  ProductVendor({
    required this.id,
    required this.vendorCode,
    required this.vendorName,
  });

  final int id;
  final String vendorCode;
  final String vendorName;
}

/// 제품의 단위(UOM) 정보.
class ProductUom {
  ProductUom({required this.id, required this.uomName});

  final int id;
  final String uomName;
}

/// 제품 생성/수정에 사용하는 입력 모델.
class ProductInput {
  ProductInput({
    required this.productCode,
    required this.productName,
    required this.vendorId,
    required this.uomId,
    this.isActive = true,
    this.note,
  });

  final String productCode;
  final String productName;
  final int vendorId;
  final int uomId;
  final bool isActive;
  final String? note;

  /// API 요청 바디로 직렬화한다.
  Map<String, dynamic> toPayload() {
    return {
      'product_code': productCode,
      'product_name': productName,
      'vendor_id': vendorId,
      'uom_id': uomId,
      'is_active': isActive,
      'note': note,
    };
  }
}
