import { ApiProperty } from '@nestjs/swagger';
import { IsJSON, IsObject, IsOptional, IsString } from 'class-validator';
import { AssetPropsSelectionOrder } from '../logic/PropsSelection';

export class AssetQueryDTOWhere {
  @ApiProperty()
  @IsString()
  @IsOptional()
  query?: string;

  @ApiProperty()
  id?: string[];

  @ApiProperty()
  workspaceId?: string;

  @ApiProperty()
  scopeId?: string[];

  @ApiProperty()
  isSystem?: boolean;
}

export class AssetQueryDTO {
  @ApiProperty({
    description:
      'json filter like {"query": "abc", "id": ["abc"], "workspaceId": "abc", "isSystem": false, "scope": "default"}',
    required: false,
  })
  @IsJSON()
  @IsOptional()
  where?: string;

  @ApiProperty({
    description: 'Limit to count',
    required: false,
  })
  @IsOptional()
  count?: number;

  @ApiProperty({
    description: 'Start from offset',
    required: false,
  })
  @IsOptional()
  offset?: number;

  @ApiProperty({
    description: 'Order by (json)',
    required: false,
  })
  @IsJSON()
  @IsOptional()
  order?: string;
}

export class AssetViewQueryDTO extends AssetQueryDTO {
  @ApiProperty({
    description: 'Group by (json)',
    required: false,
  })
  @IsOptional()
  @IsJSON()
  group?: string;

  @ApiProperty({
    description: 'Select (json)',
    required: true,
  })
  @IsJSON()
  select: string;
}

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

  @ApiProperty({
    description: 'Limit to count',
    required: false,
  })
  @IsOptional()
  count?: number;

  @ApiProperty({
    description: 'Start from offset',
    required: false,
  })
  @IsOptional()
  offset?: number;

  @ApiProperty({
    description: 'Order by',
    required: false,
  })
  @IsOptional()
  order?: AssetPropsSelectionOrder[];
}

export class AssetViewQueryPostDTO extends AssetQueryPostDTO {
  @ApiProperty({
    description: 'Group by',
    required: false,
  })
  @IsOptional()
  group?: AssetPropsSelectionOrder[];

  @ApiProperty({
    description: 'Select',
    required: true,
  })
  select: AssetPropsSelectionOrder[];
}
