import type { ChatEvent } from '../../../../shared-kernel';
import type { ChatAttachmentAnnouncement } from '../../../../shared-kernel';

export type FileAnnounceEvent = ChatEvent & {
  type: 'file-announce';
  messageId: string;
  file: ChatAttachmentAnnouncement;
};

export type FileChunkEvent = ChatEvent & {
  type: 'file-chunk';
  messageId: string;
  fileId: string;
  index: number;
  total: number;
  data: string;
  fromPeerId?: string;
};

export type FileRequestEvent = ChatEvent & {
  type: 'file-request';
  messageId: string;
  fileId: string;
  fromPeerId?: string;
};

export type FileCancelEvent = ChatEvent & {
  type: 'file-cancel';
  messageId: string;
  fileId: string;
  fromPeerId?: string;
};

export type FileNotFoundEvent = ChatEvent & {
  type: 'file-not-found';
  messageId: string;
  fileId: string;
};

export type FileAnnouncePayload = Pick<ChatEvent, 'messageId' | 'file'>;

export interface FileChunkPayload {
  messageId?: string;
  fileId?: string;
  fromPeerId?: string;
  index?: number;
  total?: number;
  data?: ChatEvent['data'];
}

export type FileRequestPayload = Pick<ChatEvent, 'messageId' | 'fileId' | 'fromPeerId'>;
export type FileCancelPayload = Pick<ChatEvent, 'messageId' | 'fileId' | 'fromPeerId'>;
export type FileNotFoundPayload = Pick<ChatEvent, 'messageId' | 'fileId'>;

export type LocalFileWithPath = File & {
  path?: string;
};
