/// Created by Haoyi on 2023/2/18

import 'package:guru_app/financial/data/db/order_database.dart';
import 'package:guru_app/financial/manifest/manifest.dart';
import 'package:guru_app/financial/product/product_model.dart';
import 'package:guru_utils/datetime/datetime_utils.dart';
import 'package:guru_utils/id/id_utils.dart';

/// Created by Haoyi on 2023/2/13

class IgcProduct implements Product {
  @override
  final ProductId productId;

  @override
  final Manifest manifest;

  final int cost;

  String get sku => productId.sku;

  IgcProduct(this.productId, this.manifest, this.cost);

  bool isConsumable() {
    return productId.isConsumable;
  }

  @override
  String toString() {
    return 'IgcProduct{productId: $productId}';
  }

  @override
  OrderEntity createOrder() {
    return OrderEntity(
        orderId: IdUtils.uuidV4(),
        sku: productId.sku,
        state: TransactionState.success,
        attr: productId.attr,
        method: TransactionMethod.igc.index,
        currency: TransactionCurrency.igc,
        cost: cost.toDouble(),
        category: manifest.category,
        timestamp: DateTimeUtils.currentTimeInMillis(),
        manifest: manifest);
  }
}
