import type { SelectItem } from '@/models/SelectItem' import { isBoursecuProject } from '@/utils/config' export const BOURSECU_GROUP_MAFTOL = 'مفتول مس' export const BOURSECU_GROUP_KATOD = 'کاتد مس' export const BOURSECU_GROUP_ABSHODE = 'آبشده' export const BOURSECU_ASSET_LABEL_KATOD = 'دارایی کاتد مس' export const BOURSECU_ASSET_LABEL_MAFTOL = 'دارایی مفتول مس' export const BOURSECU_ASSET_LABEL_GOLD = 'دارایی طلایی' const DEFAULT_TYPE_DEAL: SelectItem[] = [ { value: 'نقدی', key: 'cash' }, { value: 'طلایی', key: 'gold' }, ] const MAFTOL_TYPE_DEAL: SelectItem[] = [ { value: BOURSECU_GROUP_KATOD, key: 'katod' }, { value: 'نقدی', key: 'cash' }, ] const CASH_ONLY_TYPE_DEAL: SelectItem[] = [ { value: 'نقدی', key: 'cash' }, ] const GOLD_ONLY_TYPE_DEAL: SelectItem[] = [ { value: 'طلایی', key: 'gold' }, ] export function normalizeProductGroupType(groupType?: string | null) { return (groupType ?? '').trim() } export function isBoursecuDealProductGroup(groupType?: string | null) { if (!isBoursecuProject()) { return false } const group = normalizeProductGroupType(groupType) return group === BOURSECU_GROUP_MAFTOL || group === BOURSECU_GROUP_KATOD || group === BOURSECU_GROUP_ABSHODE } export function isMaftolMesGroup(groupType?: string | null) { return normalizeProductGroupType(groupType) === BOURSECU_GROUP_MAFTOL } export function isKatodMesGroup(groupType?: string | null) { return normalizeProductGroupType(groupType) === BOURSECU_GROUP_KATOD } export function isGoldOnlyDealGroup(groupType?: string | null) { return normalizeProductGroupType(groupType) === BOURSECU_GROUP_ABSHODE } export function getProductDealMethodOptions(groupType?: string | null): SelectItem[] { if (!isBoursecuProject()) { return DEFAULT_TYPE_DEAL } if (isMaftolMesGroup(groupType)) { return MAFTOL_TYPE_DEAL } if (isKatodMesGroup(groupType)) { return CASH_ONLY_TYPE_DEAL } if (isGoldOnlyDealGroup(groupType)) { return GOLD_ONLY_TYPE_DEAL } return DEFAULT_TYPE_DEAL } export function getDefaultProductDealMethod(groupType?: string | null) { return getProductDealMethodOptions(groupType)[0]?.key ?? 'cash' } export function isCashLikeDealMethod(method?: string | null) { return method === 'cash' || method === 'katod' } export const BOURSECU_WALLET_LABEL_GENERIC = 'موجودی کیف' export function getGoldWalletLabel(groupType?: string | null) { if (!isBoursecuProject()) return 'موجودی کیف طلا' const group = normalizeProductGroupType(groupType) if (group === BOURSECU_GROUP_KATOD) return `موجودی کیف ${BOURSECU_GROUP_KATOD}` if (group === BOURSECU_GROUP_MAFTOL) return `موجودی کیف ${BOURSECU_GROUP_MAFTOL}` if (group === BOURSECU_GROUP_ABSHODE) return 'موجودی کیف طلا' return BOURSECU_WALLET_LABEL_GENERIC } export function getCashWalletLabel(groupType?: string | null) { if (!isBoursecuProject()) return 'موجودی کیف پول' const group = normalizeProductGroupType(groupType) if (group === BOURSECU_GROUP_KATOD) return `موجودی کیف ${BOURSECU_GROUP_KATOD}` if (group === BOURSECU_GROUP_MAFTOL) return `موجودی کیف ${BOURSECU_GROUP_MAFTOL}` return BOURSECU_WALLET_LABEL_GENERIC } export function getWeightUnit() { return isBoursecuProject() ? 'کیلوگرم' : 'گرم' } export function formatBoursecuAssetAmount(amount?: number | null) { return `${amount ?? 0}${getWeightUnit()}` } export function formatGoldWalletBalanceText(gold: number, groupType?: string | null) { return `${getGoldWalletLabel(groupType)}: ${gold} ${getWeightUnit()}` } export function formatCashWalletBalanceText(cashFormatted: string | number, groupType?: string | null) { return `${getCashWalletLabel(groupType)}: ${cashFormatted} ریال` } export function getInsufficientGoldWalletMessage(groupType?: string | null) { return `${getGoldWalletLabel(groupType)} ناکافی است` } export function getInsufficientCashWalletMessage(groupType?: string | null) { return `${getCashWalletLabel(groupType)} ناکافی است` }