/**
 * Convesations
 */
export enum MESSAGE_CONVERSATION_TYPES {
    "USER_TO_USER" = "user-to-user",
    "USER_TO_ORG" = "user-to-org",
}

export type FindMessageConversationsParams = {
    _id?: string;
    userIdFrom?: string;
    userIdTo?: string;
    companyId?: string;
    sessionUser: string;
};

export type PaginateMessageConversationsParams = {
    query?: string;
    userIdFrom?: string;
    userIdTo?: string;
    companyId?: string;
    page: number;
    limit: number;
    sessionUser: string;
};

export type PaginateMessageConversationsResults = {
    data: IMessageConversation[];
    page: number;
    pages: number;
};

export type FindConversationsResults = {
    data: FindConversationItem[];
    page: number;
    pages: number;
};

export type CreateMessageConversationParams = {
    userIdFrom?: string;
    userIdTo?: string;
    companyId?: string;
    type: MESSAGE_CONVERSATION_TYPES;
    sessionUser: string;
};

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

export interface IMessageConversation {
    id?: string;
    userIdFrom?: string; //Indica quien envía el mensaje
    userIdTo?: string; // Indica a que usuario va dirigido el mensaje.
    //                    Cuando el mensaje va dirigido a una organizacion,
    //                    habrá un colaborador de la organizacion que de una respuesta
    //                    y ese id de usuario se almacenara en userIdTo.
    companyId?: string; //Indica que el mensaje va dirigido a una organizacion.
    type: MESSAGE_CONVERSATION_TYPES;
    newMessages: number; //Indica si hay nuevos mensajes.
}

export interface FindConversationItem {
    conversation: IMessageConversation;
    name: string;
    description: string;
    image: string;
    orderWeight: number;
}

export type PaginateFindContactsParams = {
    query?: string;
    page: number;
    limit: number;
    sessionUser: string;
};

export type PaginateFindContactsResults = {
    data: FindConversationItem[];
    page: number;
    pages: number;
};

export type MarkConversationAsReadParams = {
    conversationId: string;
    sessionUser: string;
};

/**
 * Mensages
 */

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;
}
