import { defineStore } from "pinia";
import axios from 'axios'


export const useMessageStore = defineStore("message", {
    state: () => ({
        lists: [],
    }),
    actions: {
        fetchLists: function (payload) {
            return new Promise((resolve, reject) => {
                axios.get(`admin/message`, {
                    params: payload
                }).then((res) => {
                    this.lists = res.data.data;
                    resolve(res);
                }).catch((err) => {
                    reject(err);
                });
            });
        },
        save: function (payload) {
            return new Promise((resolve, reject) => {
                let method = axios.post;
                method("/admin/message", payload).then((res) => {
                    this.lists = {
                        user_id: payload.user_id,
                    };
                    resolve(res);
                }).catch((err) => {
                    reject(err);
                });
            });
        },
        changeStatus: function (payload) {
            return new Promise((resolve, reject) => {
                axios.get(`admin/message/change-status/${payload.message_id}/${payload.user_id}`, payload).then((res) => {
                    resolve(res);
                }).catch((err) => {
                    reject(err);
                });
            });
        },
    },
});
