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

class ProductVariants extends Table {
  TextColumn get localId => text().clientDefault(() => const Uuid().v7().toString())();
  TextColumn get serverId => text().nullable()();
  TextColumn get productId => text().references(Products, #localId)();
  TextColumn get name => text()();
  TextColumn get localImagePath => text().nullable()();
  TextColumn get serverImageUrl => text().nullable()();
  BoolColumn get isVisibleOnline =>
      boolean().withDefault(const Constant(false))();
  IntColumn get totalRating => integer().withDefault(const Constant(0))();
  RealColumn get averageRating => real().withDefault(const Constant(0.0))();
  RealColumn get totalSold => real().withDefault(const Constant(0.0))();
  BoolColumn get isProductVariant => boolean().withDefault(const Constant(false))();
  TextColumn get syncStatus => text().withDefault(const Constant('dirty'))();
  DateTimeColumn get createdAt => dateTime().withDefault(currentDateAndTime)();
  DateTimeColumn get updatedAt => dateTime().withDefault(currentDateAndTime)();
  DateTimeColumn get deletedAt => dateTime().nullable()();

  @override
  Set<Column<Object>>? get primaryKey => {localId};
}
