import { createSlice } from "@reduxjs/toolkit"
import { User } from "../../models/User";
import { IChat } from "../../models/IChat";
import { faker } from '@faker-js/faker';
import { IMessage } from "../../models/IMessage";

export interface MessengerState {
    chats: IChat[];
    chat: {
        user: User,
        messages: IMessage[]
    }
    isLoading: boolean;
}


const initialState: MessengerState = {
    chats: [
        {_id: faker.string.uuid(), name: faker.person.firstName(), sname: faker.person.lastName(), avatar: faker.internet.avatar(), unreaded: 1, isOnline: true, lastmsg: {_id: faker.string.uuid(), msg: faker.lorem.sentence(), time: faker.date.anytime()}},
        {_id: faker.string.uuid(), name: faker.person.firstName(), sname: faker.person.lastName(), avatar: faker.internet.avatar(), unreaded: 4, isOnline: false, lastmsg: {_id: faker.string.uuid(), msg: faker.lorem.sentence(), time: faker.date.anytime()}},
        {_id: faker.string.uuid(), name: faker.person.firstName(), sname: faker.person.lastName(), avatar: faker.internet.avatar(), unreaded: 0, isOnline: true, lastmsg: {_id: faker.string.uuid(), msg: faker.lorem.sentence(), time: faker.date.anytime()}},
        {_id: faker.string.uuid(), name: faker.person.firstName(), sname: faker.person.lastName(), avatar: faker.internet.avatar(), unreaded: 0, isOnline: false, lastmsg: {_id: faker.string.uuid(), msg: faker.lorem.sentence(), time: faker.date.anytime()}},
        {_id: faker.string.uuid(), name: faker.person.firstName(), sname: faker.person.lastName(), avatar: faker.internet.avatar(), unreaded: 0, isOnline: true, lastmsg: {_id: faker.string.uuid(), msg: faker.lorem.sentence(), time: faker.date.anytime()}},
        {_id: faker.string.uuid(), name: faker.person.firstName(), sname: faker.person.lastName(), avatar: faker.internet.avatar(), unreaded: 1, isOnline: true, lastmsg: {_id: faker.string.uuid(), msg: faker.lorem.sentence(), time: faker.date.anytime()}},
        {_id: faker.string.uuid(), name: faker.person.firstName(), sname: faker.person.lastName(), avatar: faker.internet.avatar(), unreaded: 4, isOnline: false, lastmsg: {_id: faker.string.uuid(), msg: faker.lorem.sentence(), time: faker.date.anytime()}},
        {_id: faker.string.uuid(), name: faker.person.firstName(), sname: faker.person.lastName(), avatar: faker.internet.avatar(), unreaded: 0, isOnline: true, lastmsg: {_id: faker.string.uuid(), msg: faker.lorem.sentence(), time: faker.date.anytime()}},
        {_id: faker.string.uuid(), name: faker.person.firstName(), sname: faker.person.lastName(), avatar: faker.internet.avatar(), unreaded: 0, isOnline: false, lastmsg: {_id: faker.string.uuid(), msg: faker.lorem.sentence(), time: faker.date.anytime()}},
        {_id: faker.string.uuid(), name: faker.person.firstName(), sname: faker.person.lastName(), avatar: faker.internet.avatar(), unreaded: 0, isOnline: true, lastmsg: {_id: faker.string.uuid(), msg: faker.lorem.sentence(), time: faker.date.anytime()}}
    ],
    chat: {
        user: {
            _id: faker.string.uuid(),
            email: faker.internet.email(),
            name: faker.person.firstName(),
            sname: faker.person.lastName(),
            avatar: faker.internet.avatar(),
            online: true,
            lastOnline: faker.date.anytime(),
        },
        messages: [
            {_id: faker.string.uuid(), msg: faker.lorem.sentence(), time: faker.date.anytime(), from: faker.string.uuid(), to: faker.string.uuid(), readed: true},
            {_id: faker.string.uuid(), msg: faker.lorem.sentence(), time: faker.date.anytime(), from: faker.string.uuid(), to: faker.string.uuid(), readed: true},
            {_id: faker.string.uuid(), msg: faker.lorem.sentence(), time: faker.date.anytime(), from: faker.string.uuid(), to: faker.string.uuid(), readed: true},
            {_id: faker.string.uuid(), msg: faker.lorem.sentence(), time: faker.date.anytime(), from: faker.string.uuid(), to: faker.string.uuid(), readed: true},
            {_id: faker.string.uuid(), msg: faker.lorem.sentence(), time: faker.date.anytime(), from: faker.string.uuid(), to: faker.string.uuid(), readed: true},
            {_id: faker.string.uuid(), msg: faker.lorem.sentence(), time: faker.date.anytime(), from: faker.string.uuid(), to: faker.string.uuid(), readed: true},
            {_id: faker.string.uuid(), msg: faker.lorem.sentence(), time: faker.date.anytime(), from: faker.string.uuid(), to: faker.string.uuid(), readed: true},
            {_id: faker.string.uuid(), msg: faker.lorem.sentence(), time: faker.date.anytime(), from: faker.string.uuid(), to: faker.string.uuid(), readed: true},
            {_id: faker.string.uuid(), msg: faker.lorem.sentence(), time: faker.date.anytime(), from: faker.string.uuid(), to: faker.string.uuid(), readed: true},
            {_id: faker.string.uuid(), msg: faker.lorem.sentence(), time: faker.date.anytime(), from: faker.string.uuid(), to: faker.string.uuid(), readed: true},
            {_id: faker.string.uuid(), msg: faker.lorem.sentence(), time: faker.date.anytime(), from: faker.string.uuid(), to: faker.string.uuid(), readed: true},
            {_id: faker.string.uuid(), msg: faker.lorem.sentence(), time: faker.date.anytime(), from: faker.string.uuid(), to: faker.string.uuid(), readed: true},
            {_id: faker.string.uuid(), msg: faker.lorem.sentence(), time: faker.date.anytime(), from: faker.string.uuid(), to: faker.string.uuid(), readed: true},
            {_id: faker.string.uuid(), msg: faker.lorem.sentence(), time: faker.date.anytime(), from: '64bc6386f0a1f55e83bf04aa', to: faker.string.uuid(), readed: true},
            {_id: faker.string.uuid(), msg: faker.lorem.sentence(), time: faker.date.anytime(), from: faker.string.uuid(), to: faker.string.uuid(), readed: true},
            {_id: faker.string.uuid(), msg: faker.lorem.sentence(), time: faker.date.anytime(), from: faker.string.uuid(), to: faker.string.uuid(), readed: true},
            {_id: faker.string.uuid(), msg: faker.lorem.sentence(), time: faker.date.anytime(), from: '64bc6386f0a1f55e83bf04aa', to: faker.string.uuid(), readed: false}
        ]
    },
    isLoading: true
}

export const messengerSlice = createSlice({
    name: 'messengerSlice',
    initialState,
    reducers: {
        storeLoad(state) {
            state.isLoading = false;
        }
    },
})

export default messengerSlice.reducer;