import 'package:drift/drift.dart';
import 'package:niogu_app/core/database/tables/purchases.dart';
import 'package:uuid/uuid.dart';

class PurchaseItems extends Table {
  TextColumn get localId => text().clientDefault(() => const Uuid().v7().toString())();
  TextColumn get serverId => text().nullable()();
  TextColumn get purchaseId => text().references(Purchases, #localId)();
  TextColumn get itemType => text()();
  TextColumn get itemId => text()();
  RealColumn get quantity => real().withDefault(const Constant(0.0))();
  TextColumn get itemImageSnapshot => text().nullable()();
  TextColumn get itemImageUrlSnapshot => text().nullable()();
  TextColumn get itemNameSnapshot => text()();
  TextColumn get itemVariantNameSnapshot => text().nullable()();
  RealColumn get purchasePriceSnaphot => real().withDefault(const Constant(0.0))();
  RealColumn get subtotal => real().withDefault(const Constant(0.0))();
  TextColumn get syncStatus => text().withDefault(const Constant('dirty'))();
  DateTimeColumn get createdAt => dateTime().withDefault(currentDateAndTime)();
  DateTimeColumn get updatedAt => dateTime().withDefault(currentDateAndTime)();

  @override
  // TODO: implement primaryKey
  Set<Column<Object>>? get primaryKey => {localId};
}