import { ApiPropertyOptional } from '@nestjs/swagger';
import {
  IsEnum,
  IsMongoId,
  IsOptional,
  IsString,
  Length,
  ValidateIf,
} from 'class-validator';

export enum PostShareTarget {
  PROFILE = 'profile',
  FRIEND = 'friend',
  EXTERNAL = 'external',
  COPY_LINK = 'copy_link',
}

export enum PostShareChannel {
  WHATSAPP = 'whatsapp',
  INSTAGRAM = 'instagram',
  MESSENGER = 'messenger',
  COPY_LINK = 'copy_link',
  SYSTEM_SHARE = 'system_share',
  OTHER = 'other',
}

export class SharePostDto {
  @ApiPropertyOptional({ enum: PostShareTarget })
  @IsOptional()
  @IsEnum(PostShareTarget)
  target?: PostShareTarget;

  @ApiPropertyOptional({ maxLength: 2200 })
  @IsOptional()
  @IsString()
  @Length(0, 2200)
  caption?: string;

  @ApiPropertyOptional()
  @ValidateIf((dto: SharePostDto) => dto.target === PostShareTarget.FRIEND || !!dto.friendId)
  @IsMongoId()
  friendId?: string;

  @ApiPropertyOptional({ enum: PostShareChannel })
  @IsOptional()
  @IsEnum(PostShareChannel)
  channel?: PostShareChannel;
}

export class SharePostToProfileDto {
  @ApiPropertyOptional({ maxLength: 2200 })
  @IsOptional()
  @IsString()
  @Length(0, 2200)
  caption?: string;
}

export class SharePostToFriendDto {
  @IsMongoId()
  friendId!: string;

  @ApiPropertyOptional({ maxLength: 2200 })
  @IsOptional()
  @IsString()
  @Length(0, 2200)
  caption?: string;
}

export class SharePostExternalDto {
  @ApiPropertyOptional({ enum: PostShareChannel })
  @IsOptional()
  @IsEnum(PostShareChannel)
  channel?: PostShareChannel;
}
