import { type PaginatedResponse, type Pagination } from 'src/utils/tableUtils';

import { type CategoryStatus, type CategoryTypes } from './constants';

export type CategoryStatusType =
  (typeof CategoryStatus)[keyof typeof CategoryStatus];

export type CategoryType = (typeof CategoryTypes)[keyof typeof CategoryTypes];

export type CategoryBase = {
  id: number;
  name: string;
  instanceId?: number;
};

export type CategoryChild = CategoryBase & {
  children?: CategoryBase[];
};

export type Category = CategoryBase & {
  children?: CategoryChild[];
};

export type CategoryItem = CategoryBase & {
  status: CategoryStatusType;
  amountOfCourses: number;
  children?: CategoryItem[];
};

export type CategoryAutocompleteOption = {
  value: number;
  label: string;
  childrenCount?: number;
  depth?: number;
};

// Params
export type GetCategoriesParams = Pick<
  Pagination,
  'page' | 'limit' | 'q' | 'order'
> & {
  includeCourses: boolean;
  status?: CategoryStatusType;
};

export type CreateCategoryParams = {
  name: string;
  parentId?: number;
};

export type DeleteCategoryParams = {
  categoryId: number;
};

export type UpdateCategoryStatusParams = {
  categoryId: number;
  status: CategoryStatusType;
};

export type UpdateCategoryParams = {
  categoryId: number;
  children: {
    id: number | undefined;
    name: string;
  }[];
  name: string;
};

// Responses
export type GetCategoriesResponse = PaginatedResponse<CategoryItem>;
export type CreateCategoryResponse = Category;
