import { Pipe, PipeTransform } from '@angular/core';
import {dictionaryData, Dictionary} from "../../data/common/dictionary.namespace";

@Pipe({
  name: 'dictionary',
  standalone: true
})
export class DictionaryPipe implements PipeTransform {

  data: Dictionary[] = dictionaryData;

  /**
   * 获取数据字典
   * @param codeType 码类型
   */
  getDictionaryList(codeType: string): any {
      return this.data.filter(o => o.codeType == codeType);
  }

  /**
   * 获取数据字典
   * @param codeType  码类型
   * @param codeValue 码值
   */
  getDictionary(codeType: string, codeValue: string): any {
    // 读取缓存数据
    return this.data.find(o => o.codeType == codeType && o.codeValue == codeValue);
  }

  transform(codeValue: string,codeType: string): string {
    const obj = this.getDictionary(codeType, codeValue);
    if (obj == null) {
      return '未知';
    } else {
      return obj.codeName;
    }
  }
}

