import type { RiskLevel, RiskTagCategory, UserRole } from '../types/riskTag';

export interface TagCatalogItem {
  tagName: string;
  tagType: RiskTagCategory;
  groupName: string;
  defaultLevel: RiskLevel;
  requiresApproval: boolean;
}

/** 标签目录 — 分组与级别对齐业务规范 */
export const TAG_CATALOG: TagCatalogItem[] = [
  // 信用与回款
  { tagName: '逾期预警', tagType: '财务', groupName: '信用与回款', defaultLevel: '中', requiresApproval: false },
  { tagName: '严重拖欠', tagType: '财务', groupName: '信用与回款', defaultLevel: '高', requiresApproval: true },
  { tagName: '频繁改账期', tagType: '财务', groupName: '信用与回款', defaultLevel: '低', requiresApproval: false },
  // 合规与法律
  { tagName: '资质存疑', tagType: '法务', groupName: '合规与法律', defaultLevel: '中', requiresApproval: false },
  { tagName: '涉诉/仲裁', tagType: '法务', groupName: '合规与法律', defaultLevel: '高', requiresApproval: true },
  { tagName: '制裁/高风险地区', tagType: '法务', groupName: '合规与法律', defaultLevel: '高', requiresApproval: true },
  // 经营与履约
  { tagName: '频繁争议', tagType: '法务', groupName: '经营与履约', defaultLevel: '中', requiresApproval: false },
  { tagName: '车辆/资产高风险', tagType: '运维', groupName: '经营与履约', defaultLevel: '高', requiresApproval: true },
  { tagName: '信息不实', tagType: '风控', groupName: '经营与履约', defaultLevel: '中', requiresApproval: false },
  // 操作与流程
  { tagName: '开票异常', tagType: '财务', groupName: '操作与流程', defaultLevel: '低', requiresApproval: false },
  { tagName: '多头签约', tagType: '风控', groupName: '操作与流程', defaultLevel: '低', requiresApproval: false },
];

export const TAG_CATALOG_MAP = Object.fromEntries(
  TAG_CATALOG.map((item) => [item.tagName, item]),
) as Record<string, TagCatalogItem>;

/** 下拉分组展示顺序 */
export const TAG_GROUPS: Array<{ groupName: string; tagNames: string[] }> = [
  { groupName: '信用与回款', tagNames: ['逾期预警', '严重拖欠', '频繁改账期'] },
  { groupName: '合规与法律', tagNames: ['资质存疑', '涉诉/仲裁', '制裁/高风险地区'] },
  { groupName: '经营与履约', tagNames: ['频繁争议', '车辆/资产高风险', '信息不实'] },
  { groupName: '操作与流程', tagNames: ['开票异常', '多头签约'] },
];

export const RISK_TAG_CATEGORIES: RiskTagCategory[] = ['法务', '财务', '运维', '风控'];

export const RISK_LEVELS: RiskLevel[] = ['低', '中', '高', '极高'];

export const HIGH_RISK_LEVELS: RiskLevel[] = ['高', '极高'];

export const ROLE_LABELS: Record<UserRole, string> = {
  finance: '财务',
  legal: '法务',
  risk: '风控',
  ops: '运维',
  sales: '销售',
  admin: '管理员',
};
