import { ApiProperty } from '@nestjs/swagger';
import { Type } from 'class-transformer';
import {
  IsArray,
  IsBoolean,
  IsNumber,
  IsObject,
  IsOptional,
  IsString,
  IsUUID,
  ValidateNested,
} from 'class-validator';

export class ProjectImportResponseLogDTO {
  @ApiProperty()
  level: 'warn' | 'error';

  @ApiProperty()
  text: string;

  constructor(level: 'warn' | 'error', text: string) {
    this.level = level;
    this.text = text;
  }
}

export class ProjectImportResponseDTO {
  @ApiProperty()
  createdAssets = 0;

  @ApiProperty()
  updatedAssets = 0;

  @ApiProperty()
  createdWorkspaces = 0;

  @ApiProperty()
  updatedWorkspaces = 0;

  @ApiProperty({
    isArray: true,
    type: ProjectImportResponseLogDTO,
  })
  logs: ProjectImportResponseLogDTO[] = [];
}

export class ProjectImportArchiveAssetReference {
  @IsString()
  @IsOptional()
  sourceBlockRef?: string | null;

  @IsUUID()
  targetAssetId: string;

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

export class ProjectImportArchiveAssetBlock {
  @IsString()
  @IsOptional()
  name?: string | null;

  @IsString()
  @IsOptional()
  title?: string | null;

  @IsString()
  @IsOptional()
  ownTitle?: string | null;

  @IsString()
  type: string;

  @IsObject()
  props: any;

  @IsNumber()
  @IsOptional()
  index?: number | null;
}

export class ProjectImportAssetFromSelector {
  @IsUUID()
  id: string;

  @IsBoolean()
  isabstract: boolean;

  @IsString()
  @IsOptional()
  name?: string | null;

  @IsUUID(undefined, { each: true })
  parentids: string[];

  @IsUUID()
  @IsOptional()
  workspaceid?: string | null;

  @IsString()
  scope: number;

  @IsString()
  @IsOptional()
  ownicon?: string | null;

  @IsString()
  @IsOptional()
  owntitle?: string | null;

  @IsNumber()
  @IsOptional()
  index?: number | null;
}

export class ProjectImportArchiveAsset {
  @IsUUID()
  id: string;

  @IsBoolean()
  isAbstract: boolean;

  @IsString()
  @IsOptional()
  name?: string | null;

  @IsUUID(undefined, { each: true })
  parentIds: string[];

  @IsUUID()
  @IsOptional()
  workspaceId?: string | null;

  @IsString()
  scope: string;

  @IsString()
  @IsOptional()
  ownIcon?: string | null;

  @IsString()
  @IsOptional()
  ownTitle?: string | null;

  @IsNumber()
  @IsOptional()
  index?: number | null;

  @IsArray()
  @ValidateNested({ each: true })
  @Type(() => ProjectImportArchiveAssetBlock)
  blocks: ProjectImportArchiveAssetBlock[];

  @IsArray()
  @ValidateNested({ each: true })
  @Type(() => ProjectImportArchiveAssetReference)
  references: ProjectImportArchiveAssetReference[];
}

export class ProjectImportArchiveWorkspace {
  @IsUUID()
  id: string;

  @IsUUID()
  @IsOptional()
  parentId?: string | null;

  @IsString()
  title?: string | null;

  @IsNumber()
  @IsOptional()
  index?: number | null;

  @IsString()
  scope: string;
}
