import type { CustomerRecord } from '../types';



export type TagCategoryCode = 'legal' | 'finance' | 'business';



export type RiskLevelCode = 'low' | 'medium' | 'high' | 'fatal';



export type TagStatusCode = 'active' | 'pending' | 'expired' | 'removed' | 'rejected';



export type TagSourceCode = 'system' | 'manual';



export type SensitiveLevel = 'normal' | 'financeSensitive' | 'legalSensitive';



export type ReviewCycleOption = '1个月' | '2个月' | '3个月' | '6个月';



export type ReviewStatusCode = 'normal' | 'dueSoon' | 'overdue';



export type ReviewConclusionCode = 'riskExists' | 'riskResolved' | 'pendingConfirmation';



export type UserRole =

  | 'sales'

  | 'legal'

  | 'finance'

  | 'businessAdmin'

  | 'ops'

  | 'riskControl'

  | 'manager'

  | 'admin';



export type RiskTagAction =

  | '新增标签'

  | '解除标签'

  | '提交审批'

  | '审批通过'

  | '审批驳回'

  | '到期复核'

  | '工作台待办'

  | '批量打标';



export interface RiskTagAttachment {

  id: string;

  name: string;

  size: string;

  uploadedAt: string;

  attachmentType?: 'legal' | 'finance' | 'general';

}



export interface FinanceSensitiveDetail {

  overdueAmount?: string;

  billNo?: string;

  receivableNote?: string;

}



export interface RiskTagReviewLog {

  id: string;

  reviewedAt: string;

  reviewedBy: string;

  conclusion: ReviewConclusionCode;

  conclusionName: string;

  note: string;

  nextReviewAt?: string;

  attachments: RiskTagAttachment[];

}



export interface CustomerRiskTag {

  id: string;

  customerId: string;

  tagCode: string;

  tagName: string;

  tagCategory: TagCategoryCode;

  tagCategoryName: string;

  responsibleDept: string;

  editableRoles: UserRole[];

  riskLevel: RiskLevelCode;

  riskLevelName: string;

  status: TagStatusCode;

  statusName: string;

  source: TagSourceCode;

  sourceName: string;

  reason: string;

  /** 打标时间（与 effectiveDate 同步） */

  taggedAt: string;

  /** @deprecated 请使用 taggedAt */

  effectiveDate: string;

  /** 财务/业管：业务有效期；法务：内部兼容字段，不在 UI 展示 */

  expireDate: string;

  /** 法务：下次复核时间 */

  nextReviewAt: string;

  reviewCycle: ReviewCycleOption | string;

  lastReviewedAt?: string;

  reviewStatus?: ReviewStatusCode;

  removedAt?: string;

  removeReason?: string;

  reviewLogs?: RiskTagReviewLog[];

  createdBy: string;

  createdAt: string;

  approvedBy?: string;

  approvedAt?: string;

  attachments: RiskTagAttachment[];

  sensitiveLevel: SensitiveLevel;

  financeDetail?: FinanceSensitiveDetail;

  rejectReason?: string;

  removalRequested?: boolean;

}



export interface RiskTagOperationLog {

  id: string;

  customerId: string;

  customerName: string;

  tagId?: string;

  tagName: string;

  tagCategory: TagCategoryCode;

  tagCategoryName: string;

  action: RiskTagAction;

  reason: string;

  statusBefore?: string;

  statusAfter?: string;

  operator: string;

  operatorRole: UserRole;

  createdAt: string;

  /** @deprecated 兼容旧日志展示 */

  detail?: string;

}



export interface RiskTagApplyForm {

  tagName: string;

  tagCategory: TagCategoryCode;

  riskLevel: RiskLevelCode;

  reason: string;

  taggedAt: string;

  /** @deprecated 与 taggedAt 同步 */

  effectiveDate: string;

  /** 财务/业管：有效期至 */

  expireDate: string;

  /** 法务：下次复核时间 */

  nextReviewAt: string;

  reviewCycle: ReviewCycleOption;

  attachments: RiskTagAttachment[];

}



export const EMPTY_RISK_TAG_FORM: RiskTagApplyForm = {

  tagName: '',

  tagCategory: 'legal',

  riskLevel: 'medium',

  reason: '',

  taggedAt: '',

  effectiveDate: '',

  expireDate: '',

  nextReviewAt: '',

  reviewCycle: '3个月',

  attachments: [],

};



export interface RiskTagReviewForm {

  conclusion: ReviewConclusionCode;

  note: string;

  nextReviewAt: string;

  removeReason: string;

  attachments: RiskTagAttachment[];

}



export const EMPTY_RISK_TAG_REVIEW_FORM: RiskTagReviewForm = {

  conclusion: 'riskExists',

  note: '',

  nextReviewAt: '',

  removeReason: '',

  attachments: [],

};



export interface MockUser {

  name: string;

  role: UserRole;

  department: string;

}



export type RiskTagsByCustomer = Record<string, CustomerRiskTag[]>;



export interface RiskTagContext {

  records: CustomerRecord[];

  riskTagsByCustomer: RiskTagsByCustomer;

  operationLogs: RiskTagOperationLog[];

}

