import { accountTypeListApi, billCodeTypeListApi, billDateTypeListApi, billUploadFileTypeListApi, differenceTypeListApi, financialBillStateListApi, getbillRateApi } from '@/api/base/basedata';
import type { ListIitem } from '@/api/base/BaseDataModel';
import { useReturnData } from '@/utils/useReturnData';
import { defineStore } from 'pinia'
//定义state类型
export type StateFinancialType<T = ListIitem> = {
    billCodeTypeList: T[]//单号类型
    billDateTypeList: T[]//账单日期类型
    financialBillStateList: T[]//应付账单状态
    billUploadFileTypeList: T[]//应付账单上传文件类型
    accountTypeList: T[]//账目类型
    billRateList: T[]//汇率版本
    differenceTypeList: T[]//差异类型接口
}
const { resData } = useReturnData()
//定义` 状态 `store
export const useStateFinancialType = defineStore('list_financialType', {
    state: (): StateFinancialType => {
        return {
            billCodeTypeList: [],
            billDateTypeList: [],
            financialBillStateList: [],
            billUploadFileTypeList: [],
            accountTypeList: [],
            billRateList: [],
            differenceTypeList: [],
        }
    },
    actions: {
        /**
         * 单号类型
         */
        async addBillCodeTypeList() {
            // 判断如果有数据就不请求接口
            if (this.billCodeTypeList.length > 0) return;
            const res = await billCodeTypeListApi()
            this.billCodeTypeList = resData(res)
        },
        /**
         * 账单日期类型
         */
        async addBillDateTypeList() {
            if (this.billDateTypeList.length > 0) return;
            const res = await billDateTypeListApi()
            this.billDateTypeList = resData(res)
        },
        /**
         * 应付账单状态
         */
        async addFinancialBillStateList() {
            if (this.financialBillStateList.length > 0) return;
            const res = await financialBillStateListApi()
            this.financialBillStateList = resData(res)
        },
        /**
         * 应付账单上传文件类型
         */
        async addBillUploadFileTypeList() {
            if (this.billUploadFileTypeList.length > 0) return;
            const res = await billUploadFileTypeListApi()
            this.billUploadFileTypeList = resData(res)
        },
        /**
         * 账目类型
         */
        async addAccountTypeList() {
            if (this.accountTypeList.length > 0) return;
            const res = await accountTypeListApi()
            this.accountTypeList = resData(res)
        },
        /**
         * 汇率版本
         */
        async addBillRateList() {
            if (this.billRateList.length > 0) return;
            const res = await getbillRateApi()
            this.billRateList = resData(res)
        },
        /**
         * 差异类型接口
         */
        async addDifferenceTypeList() {
            if (this.differenceTypeList.length > 0) return;
            const res = await differenceTypeListApi()
            this.differenceTypeList = resData(res)
        },
    },
    getters: {
        getBillCodeTypeList(state) {
            return state.billCodeTypeList;
        },
        getBillDateTypeList(state) {
            return state.billDateTypeList;
        },
        getFinancialBillStateList(state) {
            return state.financialBillStateList;
        },
        getBillUploadFileTypeList(state) {
            return state.billUploadFileTypeList;
        },
        getAccountTypeList(state) {
            return state.accountTypeList
        },
        getBillRateList(state) {
            return state.billRateList
        },
        getDifferenceTypeList(state) {
            return state.differenceTypeList
        }
    }
})