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": {
    Company: {
      id: Generated<string>;
      legalName: string;
      taxId: string | null;
      registrationNumber: string | null;
      baseCurrencyId: string | null;
      street: string | null;
      city: string | null;
      state: string | null;
      postalCode: string | null;
      country: string | null;
      status: string;
      createdAt: Generated<Timestamp>;
      updatedAt: Timestamp | null;
    }

    Department: {
      id: Generated<string>;
      code: string;
      name: string;
      companyId: string;
      parentDepartmentId: string | null;
      status: string;
      createdAt: Generated<Timestamp>;
      updatedAt: Timestamp | null;
    }

    Site: {
      id: Generated<string>;
      name: string;
      type: string;
      companyId: string;
      street: string;
      city: string;
      state: string | null;
      postalCode: string;
      country: string;
      timezone: string;
      status: string;
      createdAt: Generated<Timestamp>;
      updatedAt: Timestamp | null;
    }

    Currency: {
      id: Generated<string>;
    }
  }
}

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>;
