import { ApiProperty } from '@nestjs/swagger';
import { IsObject } from 'class-validator';
import { AssetBlockDTO } from './block-dto';
import { AssetQueryDTOWhere } from './asset-query-dto';
import { AssetPropValue } from '../logic/Props';
import { AssetRefDTO } from './asset-reference-dto';
import { CommentBlockDTO } from './comment-dto';

export class AssetCommentDTO {
  @ApiProperty()
  id: string;

  @ApiProperty()
  assetId: string;

  @ApiProperty({ type: CommentBlockDTO })
  blocks: CommentBlockDTO[];
}

export class AssetShortDTO {
  @ApiProperty({})
  id: string;

  @ApiProperty({})
  typeIds: string[];

  @ApiProperty({})
  name: string | null;

  @ApiProperty({})
  title: string;

  @ApiProperty({})
  icon: string | null;

  @ApiProperty({})
  workspaceId: string | null;

  @ApiProperty({ default: false })
  isAbstract: boolean;

  @ApiProperty({})
  scope: string;

  @ApiProperty({ type: Date })
  createdAt: string;

  @ApiProperty({ type: Date })
  updatedAt: string;

  @ApiProperty({ type: Date })
  deletedAt: string | null;

  @ApiProperty()
  rights: number;

  @ApiProperty()
  readinessRate: number;

  @ApiProperty()
  index: number | null;
}

export class AssetViewDTO {
  [x: string]: AssetPropValue;
}

export class AssetWhereRequestDTO {
  @ApiProperty({ type: () => AssetQueryDTOWhere })
  @IsObject()
  where: AssetQueryDTOWhere;
}

export class AssetFullDTO extends AssetShortDTO {
  @ApiProperty({})
  parentIds: string[];

  @ApiProperty({})
  ownTitle: string;

  @ApiProperty({})
  ownIcon: string | null;

  @ApiProperty({ type: () => AssetBlockDTO, isArray: true })
  blocks: AssetBlockDTO[];

  @ApiProperty({ isArray: true, type: AssetRefDTO })
  references: AssetRefDTO[];

  @ApiProperty({ type: AssetCommentDTO })
  comments: AssetCommentDTO[];
}
