import { ApiProperty } from '@nestjs/swagger';
import type { Category as PrismaCategory } from '@prisma/client';

export class CategoryNodeDto {
  @ApiProperty({ description: 'Category ID (bigint serialized as string)' })
  id!: string;

  @ApiProperty()
  categoryName!: string;

  @ApiProperty({ nullable: true })
  categoryIcon!: string | null;

  @ApiProperty({ nullable: true })
  sdsCategoryId!: string | null;

  @ApiProperty({ nullable: true, description: 'Parent category ID' })
  parentCategoryId!: string | null;

  @ApiProperty({ type: [CategoryNodeDto] })
  children!: CategoryNodeDto[];

  static from(category: PrismaCategory, children: CategoryNodeDto[] = []): CategoryNodeDto {
    return {
      id: category.id.toString(),
      categoryName: category.categoryName,
      categoryIcon: category.categoryIcon,
      sdsCategoryId: category.sdsCategoryId,
      parentCategoryId: category.parentCategoryId
        ? category.parentCategoryId.toString()
        : null,
      children,
    };
  }
}
