import { createReducer } from '@reduxjs/toolkit';
import { IChatPayload } from '../../../typescript/redux/chat/interfaces';
import { TChat} from '../../../typescript/redux/chat/types';

import {
  actionSelectChat,
  actionGetChatById,
  actionRemoveChat
} from '../action';

const initialState: TChat = {
     name: '',
     lastName: '',
     originalName: '',
     originalLastName: '',
     avatarUrl:'',
     color: '',
     online: '',
     lastMessage: '',
     lastMessageCreatedAt:'',
     mute: false,
     sort:false,
     seen: 0,
     total: 0,
     watched: false,
     typing: false,
     number:'',
     _id: '',
     companionId: '',
     owner: '',
     createdAt: '',
     updatedAt: '',
    __v: 0,
}

const reducerChat = createReducer(initialState, {
  [actionSelectChat.type]: (_,{ payload }:IChatPayload) => {
    return payload
  },
  [actionGetChatById.type]: (_,{ payload }:IChatPayload) => {
    return payload
  },
  [actionRemoveChat.type]: (_state,_) => {
    return initialState
  },    
});

export default reducerChat;
