import { describe, it, expect } from 'vitest'
import {
  getOrganizationalLevelName,
  getPersonnelLevelName,
  getPersonnelStatusName,
  getApprovalStatusName,
  getApprovalTypeName,
  formatNumber,
  formatPercentage
} from './index'
import { 
  OrganizationalLevel, 
  PersonnelLevel, 
  PersonnelStatus, 
  ApprovalStatus, 
  ApprovalRequestType 
} from '@/types'

describe('Utility Functions', () => {
  describe('getOrganizationalLevelName', () => {
    it('should return correct name for Division', () => {
      expect(getOrganizationalLevelName(OrganizationalLevel.Division)).toBe('师团')
    })

    it('should return correct name for Regiment', () => {
      expect(getOrganizationalLevelName(OrganizationalLevel.Regiment)).toBe('团')
    })

    it('should return correct name for Battalion', () => {
      expect(getOrganizationalLevelName(OrganizationalLevel.Battalion)).toBe('营')
    })

    it('should return correct name for Company', () => {
      expect(getOrganizationalLevelName(OrganizationalLevel.Company)).toBe('连')
    })
  })

  describe('getPersonnelLevelName', () => {
    it('should return correct name for Division level personnel', () => {
      expect(getPersonnelLevelName(PersonnelLevel.Division)).toBe('师级人才')
    })

    it('should return correct name for Regiment level personnel', () => {
      expect(getPersonnelLevelName(PersonnelLevel.Regiment)).toBe('团级人才')
    })

    it('should return correct name for Battalion level personnel', () => {
      expect(getPersonnelLevelName(PersonnelLevel.Battalion)).toBe('营级人才')
    })

    it('should return correct name for Company level personnel', () => {
      expect(getPersonnelLevelName(PersonnelLevel.Company)).toBe('连级人才')
    })
  })

  describe('getPersonnelStatusName', () => {
    it('should return correct name for Pending status', () => {
      expect(getPersonnelStatusName(PersonnelStatus.Pending)).toBe('待审批')
    })

    it('should return correct name for Approved status', () => {
      expect(getPersonnelStatusName(PersonnelStatus.Approved)).toBe('已批准')
    })

    it('should return correct name for Rejected status', () => {
      expect(getPersonnelStatusName(PersonnelStatus.Rejected)).toBe('已拒绝')
    })
  })

  describe('getApprovalStatusName', () => {
    it('should return correct name for Pending status', () => {
      expect(getApprovalStatusName(ApprovalStatus.Pending)).toBe('待审批')
    })

    it('should return correct name for Approved status', () => {
      expect(getApprovalStatusName(ApprovalStatus.Approved)).toBe('已批准')
    })

    it('should return correct name for Rejected status', () => {
      expect(getApprovalStatusName(ApprovalStatus.Rejected)).toBe('已拒绝')
    })
  })

  describe('getApprovalTypeName', () => {
    it('should return correct name for AllocationModification', () => {
      expect(getApprovalTypeName(ApprovalRequestType.AllocationModification)).toBe('配额修改')
    })

    it('should return correct name for ReportModification', () => {
      expect(getApprovalTypeName(ApprovalRequestType.ReportModification)).toBe('上报修改')
    })

    it('should return correct name for PersonnelModification', () => {
      expect(getApprovalTypeName(ApprovalRequestType.PersonnelModification)).toBe('人员修改')
    })
  })

  describe('formatNumber', () => {
    it('should format number with default 2 decimals', () => {
      expect(formatNumber(123.456)).toBe('123.46')
    })

    it('should format number with specified decimals', () => {
      expect(formatNumber(123.456, 1)).toBe('123.5')
    })

    it('should format integer with decimals', () => {
      expect(formatNumber(100, 2)).toBe('100.00')
    })
  })

  describe('formatPercentage', () => {
    it('should format rate as percentage', () => {
      expect(formatPercentage(0.75)).toBe('75.0%')
    })

    it('should format 100% correctly', () => {
      expect(formatPercentage(1)).toBe('100.0%')
    })

    it('should format 0% correctly', () => {
      expect(formatPercentage(0)).toBe('0.0%')
    })

    it('should handle rates over 100%', () => {
      expect(formatPercentage(1.5)).toBe('150.0%')
    })
  })
})
