import { ApiProperty } from '@nestjs/swagger';
import {
  IsString,
  IsNotEmpty,
  IsOptional,
  IsEnum,
  IsBoolean,
  IsInt,
  IsNumber,
  IsJSON,
} from 'class-validator';
import {
  ApiFilterParamsDecorator,
  ApiGetListParams,
} from '../../common/types/api-filter-params';
import {
  FilterProp,
  FilterPropTypes,
} from '../../common/types/filter-prop-decorators';
import { Lang } from '../../constants';
import { UserRoleDTO } from '../../user/dto/user-role-dto';
import { ProjectLicenseDTO } from '../../license/dto/license-dto';

export class CreateProjectDTO {
  @IsString()
  @IsNotEmpty()
  @ApiProperty({})
  title: string;

  @IsNumber()
  @IsNotEmpty()
  @ApiProperty({})
  timezoneShift: number;
}

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

  @ApiProperty({})
  title: string;

  @ApiProperty({})
  shortLink: string;

  @ApiProperty({})
  lang: Lang;

  @ApiProperty({})
  timezoneShift: number;
}

export class ProjectMemberDTO {
  @ApiProperty({})
  id: number;
  @ApiProperty({})
  name: string;
}

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

  @ApiProperty({})
  title: string;

  @ApiProperty({})
  shortLink: string;

  @ApiProperty({})
  lang: Lang;

  @ApiProperty({})
  timezoneShift: number;

  @ApiProperty({})
  isPublicGdd: boolean;

  @ApiProperty({})
  isPublicTasks: boolean;

  @ApiProperty({})
  isPublicAbout: boolean;

  @ApiProperty({})
  isPublicPulse: boolean;

  @ApiProperty({})
  isUnsafeContent: boolean;

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

  @ApiProperty({
    type: ProjectLicenseDTO,
  })
  license: ProjectLicenseDTO;

  @ApiProperty({ type: ProjectMemberDTO, isArray: true })
  members: ProjectMemberDTO[];
}

export class ChangeProjectSettingsDTO {
  @IsString()
  @IsOptional()
  @ApiProperty({})
  title?: string;

  @IsString()
  @IsOptional()
  @ApiProperty({})
  shortLink?: string;

  @IsNumber()
  @IsOptional()
  @ApiProperty({})
  timezoneShift?: number;

  @IsEnum(Lang)
  @IsOptional()
  @ApiProperty({})
  lang?: Lang;

  @IsBoolean()
  @IsOptional()
  @ApiProperty({})
  isPublicGdd?: boolean;

  @IsBoolean()
  @IsOptional()
  @ApiProperty({})
  isPublicTasks?: boolean;

  @IsBoolean()
  @IsOptional()
  @ApiProperty({})
  isPublicAbout?: boolean;

  @IsBoolean()
  @IsOptional()
  @ApiProperty({})
  isPublicPulse?: boolean;

  @IsBoolean()
  @IsOptional()
  @ApiProperty({})
  isUnsafeContent?: boolean;
}

export class ProjectQueryDTOWhere {
  @FilterProp(FilterPropTypes.STRING)
  query: string;
}

@ApiFilterParamsDecorator(ProjectQueryDTOWhere)
export class ProjectQueryDTO extends ApiGetListParams<ProjectQueryDTOWhere> {}

export class TemplateQueryDTOWhere {}

@ApiFilterParamsDecorator(TemplateQueryDTOWhere)
export class TemplateQueryDTO extends ApiGetListParams<TemplateQueryDTOWhere> {}

export class MemberQueryDTOWhere {
  @FilterProp([FilterPropTypes.INTEGER])
  ids?: number[];

  @FilterProp([FilterPropTypes.INTEGER])
  roleNums?: number[];
}

@ApiFilterParamsDecorator(MemberQueryDTOWhere)
export class MemberQueryDTO extends ApiGetListParams<MemberQueryDTOWhere> {}

export class MemberDTO {
  @ApiProperty({})
  id: number;

  @ApiProperty({})
  name: string;

  @ApiProperty({})
  email: string;

  @ApiProperty({})
  role: UserRoleDTO;
}

export class ChangeMemberDTO {
  @IsInt()
  @IsOptional()
  @ApiProperty({})
  roleNum?: number;

  @IsString()
  @IsOptional()
  @ApiProperty({})
  username?: string;
}

export class CheckShortLinkDTO {
  @IsString()
  @IsOptional()
  @ApiProperty({})
  link?: string;
}

export class PqDTO {
  @IsJSON()
  @ApiProperty({})
  pq: string;
}

export class ExportProjectDTO {
  @IsJSON()
  @IsOptional()
  @ApiProperty()
  where: string;
}
