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

class OrderItems extends Table {
  TextColumn get localId => text().clientDefault(() => const Uuid().v7().toString())();
  TextColumn get serverId => text().nullable()();
  TextColumn get orderId => text().references(Orders, #localId)();
  TextColumn get productVariantId => text().references(ProductVariants, #localId)();
  RealColumn get quantity => real().withDefault(const Constant(0))();
  TextColumn get productImageSnapshot => text().nullable()();
  TextColumn get productImageUrlSnapshot => text().nullable()();
  TextColumn get productNameSnapshot => text()();
  TextColumn get productVariantNameSnapshot => text().nullable()();
  RealColumn get sellingPriceSnapshot => real().withDefault(const Constant(0))();
  RealColumn get subtotal => real().withDefault(const Constant(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};
}