/**
 * 账务相关类型定义
 */

/**
 * 科目类别
 */
export type SubjectCategory = 'asset' | 'liability' | 'income' | 'expense'

/**
 * 借贷方向
 */
export type Direction = 'debit' | 'credit'

/**
 * 分录状态
 */
export type EntryStatus = 'pending' | 'posted' | 'reversed'

/**
 * 会计科目
 */
export interface AccountingSubject {
  code: string
  name: string
  category: SubjectCategory
  direction_default: number
  parent_code?: string
  level: number
}

/**
 * 分录明细行
 */
export interface LedgerLine {
  id: number
  entry_id: number
  account_id: number
  account_type: string
  subject_code: string
  direction: Direction
  amount: string
}

/**
 * 记账分录
 */
export interface LedgerEntry {
  id: number
  entry_no: string
  txn_no: string
  post_date: string
  post_time: string
  description?: string
  status: EntryStatus
  created_at: string
  lines: LedgerLine[]
}

/**
 * 分录查询参数
 */
export interface LedgerEntryQuery {
  subject_code?: string
  start_date?: string
  end_date?: string
  status?: EntryStatus
  page?: number
  page_size?: number
}

/**
 * 科目类别显示名称映射
 */
export const SubjectCategoryLabels: Record<SubjectCategory, string> = {
  asset: '资产类',
  liability: '负债类',
  income: '收入类',
  expense: '支出类',
}

/**
 * 借贷方向显示名称映射
 */
export const DirectionLabels: Record<Direction, string> = {
  debit: '借方',
  credit: '贷方',
}

/**
 * 分录状态显示名称映射
 */
export const EntryStatusLabels: Record<EntryStatus, string> = {
  pending: '待确认',
  posted: '已过账',
  reversed: '已冲销',
}

/**
 * 预定义会计科目
 */
export const PredefinedSubjects: AccountingSubject[] = [
  { code: '1002', name: '银行存款', category: 'asset', direction_default: 1, level: 1 },
  { code: '1003', name: '在途资金', category: 'asset', direction_default: 1, level: 1 },
  { code: '2001', name: '客户存款', category: 'liability', direction_default: -1, level: 1 },
  { code: '2002', name: '待清算款项', category: 'liability', direction_default: -1, level: 1 },
  { code: '3001', name: '手续费收入', category: 'income', direction_default: -1, level: 1 },
  { code: '4001', name: '利息支出', category: 'expense', direction_default: 1, level: 1 },
]

