import {defineStore} from "pinia";
import {ref} from "vue";

import { getProgramList,getCoachList,getQuestionnaireList,getCoachProgramList,getTeamListById,getEmailModelList } from '@/api/agent/index.js'

export const useAgentStore = defineStore('agent', () => {
    const programList = ref([]);
    const programMap = ref(new Map());
    const getProgramData = () => {
        getProgramList({page:1,limit:-1,programName:''}).then((res) => {
            programList.value = res.data.list;
            const map = new Map();
            programList.value.forEach((supplier) => {
                map.set(supplier.id, supplier);
            });
            programMap.value = map;
        });
    };

    const companyList = ref([]);
    const companyMap = ref(new Map());
    const getCompanyData = () => {
        getCoachProgramList({enterpriseName:''}).then((res) => {
            companyList.value = res.data;
            const map = new Map();
            companyList.value.forEach((supplier) => {
                map.set(supplier.id, supplier);
            });
            companyMap.value = map;
        });
    };

    const teamList = ref([]);
    const teamMap = ref(new Map());
    const getTeamData = () => {
        getTeamListById({enterpriseId:''}).then((res) => {
            teamList.value = res.data;
            const map = new Map();
            teamList.value.forEach((supplier) => {
                map.set(supplier.id, supplier);
            });
            teamMap.value = map;
        });
    };

    const coachList = ref([]);
    const coachMap = ref(new Map());
    const getCoachData = () => {
        getCoachList({page:1,limit:-1}).then((res) => {
            coachList.value = res.data.list;
            const map = new Map();
            coachList.value.forEach((supplier) => {
                map.set(supplier.id, supplier);
            });
            coachMap.value = map;
        });
    };

    const questionnaireList = ref([]);
    const questionnaireMap = ref(new Map());
    const getQuestionnaireData = () => {
        getQuestionnaireList({page:1,limit:-1}).then((res) => {
            questionnaireList.value = res.data.list;
            const map = new Map();
            questionnaireList.value.forEach((supplier) => {
                map.set(supplier.id, supplier);
            });
            questionnaireMap.value = map;
        });
    };

    const emailModelList = ref([]);
    const emailModelMap = ref(new Map());
    const getEmailModelData = () => {
        getEmailModelList({page:1,limit:-1,name:''}).then((res) => {
            emailModelList.value = res.data.list;
            const map = new Map();
            emailModelList.value.forEach((supplier) => {
                map.set(supplier.id, supplier);
            });
            emailModelMap.value = map;
        });
    };

    return {
        programList,
        programMap,
        getProgramData,
        companyList,
        companyMap,
        getCompanyData,
        teamList,
        teamMap,
        getTeamData,
        coachList,
        coachMap,
        getCoachData,
        questionnaireList,
        questionnaireMap,
        getQuestionnaireData,
        emailModelList,
        emailModelMap,
        getEmailModelData,
    };
})
