import { useEnumStore } from '@/stores'
import { usePerformanceStore } from '@/stores'

const { getEnumTypes, getEnumTypeList, getEnumTypeName } = useEnumStore()
const enumKeys = ['wrApplyStatus', 'performanceStatus', 'stepStatus'] as const
const enumMap = getEnumTypes(...enumKeys)

/**
 * 买卖方向
 */
export enum BuyOrSell {
    Buy = 0, // 买
    Sell = 1, // 卖
}

/**
 * 获取买卖方向列表
 * @returns 
 */
export function getBuyOrSellList() {
    return [
        { label: '购买', value: BuyOrSell.Buy },
        { label: '出售', value: BuyOrSell.Sell },
    ]
}

/**
 * 获取买卖方向名称
 * @returns 
 */
export function getBuyOrSellName(value: number) {
    return getEnumTypeName(getBuyOrSellList(), value)
}

/**
 * 申请状态
 */
export enum ApplyStatus {
    Pending = 1, // 待确认
}

/**
 * 获取申请状态列表
 * @returns 
 */
export function getApplyStatusList() {
    return getEnumTypeList(enumMap.get('wrApplyStatus'))
}

/**
 * 获取申请状态名称
 * @returns 
 */
export function getApplyStatusName(value: number) {
    return getEnumTypeName(getApplyStatusList(), value)
}

/**
 * 获取履约状态列表
 * @returns 
 */
export function getPerformanceStatusList() {
    return getEnumTypeList(enumMap.get('performanceStatus'))
}

/**
 * 获取履约状态名称
 * @returns 
 */
export function getPerformanceStatusName(value: number) {
    return getEnumTypeName(getPerformanceStatusList(), value)
}

/**
 * 履约步骤
 */
export enum StepType {
    Payment = 1, // 买方支付
    Receive = 2, // 卖方收款
    Pickup = 3, // 买方自提
    SendGoods = 4, // 卖方发货
    ConfirmGoods = 5, // 买方确认货
    SendInvoice = 6, // 卖方发票
    ConfirmInvoice = 7, // 买方确认票
    WRMove = 8, // 仓单转移
}

/**
 * 获取履约步骤类型列表
 * @returns 
 */
export function getStepTypeList() {
    const { performanceStepTypes } = usePerformanceStore()
    return performanceStepTypes.value.map((e) => ({
        label: e.steptypename,
        value: e.steptypeid,
    }))
}

/**
 * 获取履约步骤类型名称
 * @returns 
 */
export function getStepTypeName(value: number) {
    return getEnumTypeName(getStepTypeList(), value)
}

/**
 * 获取履约步骤状态列表
 * @returns 
 */
export function getStepStatusList() {
    return getEnumTypeList(enumMap.get('stepStatus'))
}

/**
 * 获取履约步骤状态名称
 * @returns 
 */
export function getStepStatusName(value: number) {
    return getEnumTypeName(getStepStatusList(), value)
}