import { ApiProperty } from '@nestjs/swagger';
import type { Tag as PrismaTag } from '@prisma/client';

export class PublicTagDto {
  @ApiProperty()
  id!: string;

  @ApiProperty()
  tagName!: string;

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

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

  @ApiProperty()
  sortOrder!: number;

  @ApiProperty({ nullable: true })
  group!: { id: string; groupName: string; sortOrder: number } | null;

  static from(tag: PrismaTag & { tagGroup?: { id: bigint; groupName: string; sortOrder: number } | null }): PublicTagDto {
    return {
      id: tag.id.toString(),
      tagName: tag.tagName,
      tagColor: tag.tagColor,
      tagFontColor: tag.tagFontColor,
      sortOrder: tag.sortOrder,
      group: tag.tagGroup
        ? {
            id: tag.tagGroup.id.toString(),
            groupName: tag.tagGroup.groupName,
            sortOrder: tag.tagGroup.sortOrder,
          }
        : null,
    };
  }
}
