import {
  createGetDB,
  type Generated,
  type Timestamp,
  type NamespaceDB,
  type NamespaceInsertable,
  type NamespaceSelectable,
  type NamespaceTable,
  type NamespaceTableName,
  type NamespaceTransaction,
  type NamespaceUpdateable,
} from "@tailor-platform/sdk/kysely";

export interface Namespace {
  "main-db": {
    Currency: {
      id: Generated<string>;
      code: string;
      name: string;
      symbol: string;
      decimalPlaces: number;
      isBaseCurrency: boolean;
      isActive: boolean;
      createdAt: Generated<Timestamp>;
      updatedAt: Timestamp | null;
    }

    ExchangeRate: {
      id: Generated<string>;
      sourceCurrencyId: string;
      targetCurrencyId: string;
      rate: number;
      effectiveDate: Timestamp;
      createdAt: Generated<Timestamp>;
      updatedAt: Timestamp | null;
    }

    Unit: {
      id: Generated<string>;
      name: string;
      symbol: string;
      categoryId: string;
      conversionFactor: number;
      roundingPrecision: number;
      isActive: boolean;
      createdAt: Generated<Timestamp>;
      updatedAt: Timestamp | null;
    }

    UoMCategory: {
      id: Generated<string>;
      name: string;
      description: string | null;
      referenceUnitId: string | null;
      isActive: boolean;
      createdAt: Generated<Timestamp>;
      updatedAt: Timestamp | null;
    }
  }
}

export const getDB = createGetDB<Namespace>();

export type DB<N extends keyof Namespace = keyof Namespace> = NamespaceDB<Namespace, N>;

export type Transaction<K extends keyof Namespace | DB = keyof Namespace> =
  NamespaceTransaction<Namespace, K>;

type TableName = NamespaceTableName<Namespace>;
export type Table<T extends TableName> = NamespaceTable<Namespace, T>;

export type Insertable<T extends TableName> = NamespaceInsertable<Namespace, T>;
export type Selectable<T extends TableName> = NamespaceSelectable<Namespace, T>;
export type Updateable<T extends TableName> = NamespaceUpdateable<Namespace, T>;
