import {
    CreateMessageConversationParams,
    IMessageConversation,
    MESSAGE_CONVERSATION_TYPES,
} from "../MessageConversations/MessagesConversations.Interface";

export type FindMessageParams = {
    id?: string;
    conversationId?: string;
    messageDate?: Date;
    readed?: boolean;
    sessionUser: string;
};

export type PaginateMessageParams = {
    query?: string;
    conversationId?: string;
    dateFrom?: Date;
    dateTo?: Date;
    readed?: boolean;
    page: number;
    limit: number;
    sessionUser: string;
};

export type PaginateMessageResults = {
    data: IMessage[];
    page: number;
    pages: number;
};

export type SendMessageParams = Omit<CreateMessageConversationParams, "type"> & {
    conversationId?: string;
    type?: MESSAGE_CONVERSATION_TYPES;
    message: string;
};

export type CreateMessageParams = {
    conversationId: string;
    message: string;
    sessionUser: string;
};

export type DeleteMessageParams = {
    id: string;
    sessionUser: string;
};

export interface IMessage {
    id?: string;
    conversationId?: string;
    messageDate?: Date; //Fecha de envío del mensaje
    readed: boolean; //Indica si el mensaje fue leido por el receptor.
    message: string; //Contenido del mensaje.
    userId: string; //Propietario del mensaje.
}

export interface ISendMessageResult {
    message: IMessage;
    conversation: IMessageConversation;
}

export interface IMessagesAdapter {
    create(data: CreateMessageParams): Promise<IMessage>;
    delete(id: string): Promise<void>;
    find(filters: FindMessageParams): Promise<IMessage[]>;
    findOne(filters: FindMessageParams): Promise<IMessage | null>;
    paginate(filters: PaginateMessageParams): Promise<PaginateMessageResults>;
    markAsRead(data: FindMessageParams): Promise<void>;
}

export interface IMessageManager {
    messages: IMessagesAdapter;
    sendMessage(data: SendMessageParams): Promise<ISendMessageResult>;
    deleteMessage(data: DeleteMessageParams): Promise<void>;
    paginateMessages(data: PaginateMessageParams): Promise<PaginateMessageResults>;
    markAsRead(data: FindMessageParams): Promise<void>;
}
