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": {
    Product: {
      id: Generated<string>;
      code: string;
      name: string;
      description: string | null;
      unitId: string;
      status: "DRAFT" | "ACTIVE" | "ARCHIVED";
      createdAt: Generated<Timestamp>;
      updatedAt: Timestamp | null;
    }

    ProductAttribute: {
      id: Generated<string>;
      code: string;
      name: string;
      createdAt: Generated<Timestamp>;
      updatedAt: Timestamp | null;
    }

    ProductAttributeAssignment: {
      id: Generated<string>;
      productId: string;
      attributeId: string;
      valueId: string;
      createdAt: Generated<Timestamp>;
      updatedAt: Timestamp | null;
    }

    ProductAttributeValue: {
      id: Generated<string>;
      attributeId: string;
      label: string;
      createdAt: Generated<Timestamp>;
      updatedAt: Timestamp | null;
    }

    ProductCategory: {
      id: Generated<string>;
      code: string;
      name: string;
      parentId: string | null;
      createdAt: Generated<Timestamp>;
      updatedAt: Timestamp | null;
    }

    ProductCategoryAssignment: {
      id: Generated<string>;
      productId: string;
      categoryId: string;
      createdAt: Generated<Timestamp>;
      updatedAt: Timestamp | null;
    }

    ProductVariant: {
      id: Generated<string>;
      productId: string;
      axisValueKey: string;
      itemId: string;
      createdAt: Generated<Timestamp>;
      updatedAt: Timestamp | null;
    }

    Item: {
      id: Generated<string>;
    }

    Unit: {
      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>;
