import 'package:drift/drift.dart';
import 'package:niogu_app/core/database/tables/categories.dart';
import 'package:niogu_app/core/database/tables/units.dart';
import 'package:niogu_app/core/utils/string_list_converter.dart';
import 'package:uuid/uuid.dart';

class Products extends Table {
  TextColumn get localId => text().clientDefault(() => const Uuid().v7().toString())();
  TextColumn get serverId => text().nullable()();
  TextColumn get categoryId => text().references(Categories, #localId)();
  TextColumn get unitId => text().references(Units, #localId)();
  TextColumn get name => text()();
  TextColumn get localImagePath =>
      text().map(StringListConverter()).nullable()();
  TextColumn get serverImageUrl =>
      text().map(StringListConverter()).nullable()();
  BoolColumn get hasVariant => 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
  // TODO: implement primaryKey
  Set<Column<Object>>? get primaryKey => {localId};
}
