import 'package:drift/drift.dart';
import 'package:niogu_app/core/database/tables/outlet_inventories.dart';
import 'package:niogu_app/core/database/tables/outlets.dart';
import 'package:niogu_app/core/database/tables/users.dart';
import 'package:uuid/uuid.dart';

class StockCards extends Table {
  TextColumn get localId => text().clientDefault(() => const Uuid().v7().toString())();
  TextColumn get serverId => text().nullable()();
  TextColumn get outletInventoryId =>
      text().references(OutletInventories, #localId)();
  TextColumn get userId => text().references(Users, #localId)();
  TextColumn get type => text()();
  TextColumn get receiveFromId =>
      text().references(Outlets, #localId).nullable()();
  RealColumn get qtyChange => real().withDefault(const Constant(0.0))();
  RealColumn get currentStock => real().withDefault(const Constant(0.0))();
  TextColumn get stockType => text().withDefault(const Constant("fixed"))();
  BoolColumn get modeChange => boolean().withDefault(const Constant(false))();
  TextColumn get modeBeforeChange => text().nullable()();
  TextColumn get modeAfterChange => text().nullable()();
  RealColumn get costPrice => real().withDefault(const Constant(0.0))();
  TextColumn get referenceId => text().nullable()();
  TextColumn get documentNumber => text().nullable()();
  TextColumn get notes => text().nullable()();
  TextColumn get syncStatus => text().withDefault(const Constant("dirty"))();
  DateTimeColumn get createdAt => dateTime().withDefault(currentDateAndTime)();

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