import { ApiProperty, getSchemaPath } from '@nestjs/swagger';
import { Type } from 'class-transformer';
import {
  IsObject,
  IsOptional,
  IsString,
  IsUUID,
  ValidateNested,
} from 'class-validator';
import { AssetPropValue } from '../logic/Props';
import { AssetQueryDTOWhere } from './asset-query-dto';
import { AssetPropAccountDTO } from './block-dto';

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

  @IsOptional()
  @ApiProperty({})
  @IsString()
  blockRef?: null | string;

  @ApiProperty({})
  @IsUUID()
  targetAssetId: string;

  @IsOptional()
  @ApiProperty({})
  @IsString()
  targetBlockRef?: null | string;
}

export class AssetRefDTO {
  @IsOptional()
  @ApiProperty({})
  @IsString()
  sourceBlockRef?: null | string;

  @ApiProperty({})
  @IsUUID()
  targetAssetId: string;

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

  @ApiProperty({})
  targetTitle: string;

  @ApiProperty({})
  targetName: string;

  @IsOptional()
  @ApiProperty({})
  @IsString()
  targetBlockRef?: null | string;

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

export class AssetsRefResultDTO {
  @ApiProperty()
  ids: string[];

  @ApiProperty({
    type: 'object',
    additionalProperties: {
      type: 'array',
      items: { $ref: getSchemaPath(AssetRefDTO) },
    },
  })
  refs: {
    [key: string]: AssetRefDTO[];
  };

  @ApiProperty()
  total: number;
}
