import { IScopeType } from './process';
import { BusinessTypeKey, MatterTypeKey } from './gather';

// 审批金额汇总组件阶段数据
export interface IAuditSummaryConfig {
  // 阶段名称
  name: string;
  // 关联步骤ID（条件下有多个步骤）
  stepIDs: string[];
}

// 审核意见组件配置
export interface IAuditCommentConfig {
  // 富文本模板
  template: string;
}

// 报表打印设置
interface IMatterReportConfig {
  component: string;
  enable: boolean;
  type: string;
  IDs: string;
}

// 事项
export interface IMatter {
  ID: string;
  gatherID: string;
  businessType: BusinessTypeKey;
  matterType: MatterTypeKey;
  parentID: string;
  name: string;
  sort: string;
  formSchema: any;
  // 组件名列表
  assembly: string[];
  dataID: string;
  // 审批金额组件配置
  auditAmountConfig?: IAuditSummaryConfig[];
  // 审核意见组件配置
  auditCommentsConfig?: IAuditCommentConfig;

  // 多文件组件合格率设置
  settlementPassingRate?: number;
  // 多文件组件区间来源可见性范围
  settlementSourceScope?: IScopeType[];
  // 多文件组件区间来源项目名称可见性范围
  settlementProjectScope?: IScopeType[];
  // 报表打印设置
  reportConfig?: IMatterReportConfig[];
}

export interface IGatherMatter extends IMatter {
  businessID: string;
}

export interface IStepMatter {
  ID: string;
  userID: string;
  gatherID: string;
  businessType: BusinessTypeKey;
  stepID: string;
  matterID: string;
  formPermission: string[];
  costPermission: string[];
  profilePermission: string[];
  auditCommentsPermission: string[];
  settlementPermission: string[];
  budgetComparePermission: string[];
  changeAuditPermission: string[];
}

export interface IGatherStepMatter extends IStepMatter {
  businessID: string;
  userID: string;
}

export interface IYsProfileTemplate {
  ID: string;
  parentID: string;
  gatherID: string;
  businessType: BusinessTypeKey;
  name: string;
  sort: string;
  enable: boolean;
  required: boolean;
  folder: boolean;
  mode: string[];
  selectMode?: string;
  fileNum?: number;
}

export interface IGatherYsProfileTemplate extends IYsProfileTemplate {
  businessID: string;
  matterID?: string;
  matterListID?: string;
  dataID?: string;
  approvalID?: string;
  creatorId: string;
  creatorName: string;
}

export interface IDynamicStep {
  ID: string;
  gatherID: string;
  businessType: BusinessTypeKey;
  stepID: string;
  nextStepID: string;
  executorID: boolean;
}

export interface IGatherDynamicStep extends IDynamicStep {
  businessID: string;
}

// 组件权限相关
export interface IProcessComponentPermission {
  // 是否可编辑
  editable: boolean;
  // 是否可查看
  viewable: boolean;
  // 能否创建项目
  createProject?: boolean;
  // 新增
  add?: boolean;
  // 审核
  audit?: boolean;
  // 增报
  addReport?: boolean;
  // 区间来源
  scopeSource?: {
    // 能否看区间来源tab
    viewable: boolean;
    // 能否看项目名称
    projectNameViewable: boolean;
  };
}

// 步骤里的的组件
export interface IProcessComponent<T = any> {
  // 组件名：'cost'、'form'...
  name: string;
  // 组件权限
  permission: IProcessComponentPermission;
  // 组件数据
  data?: T | null;
  // 组件标题
  componentTitle?: string;
  // 是否有报表打印
  isPrint?: boolean;
}

// 步骤里的事项
export interface IProcessMatter {
  // 事项ID
  matterID: string;
  // 事项可用组件
  components: IProcessComponent[];
}

// 前端展示需要用的事项数据结构
export interface IMatterNode {
  ID: string;
  seq: number;
  parentID: string;
  name: string;
  components: IProcessComponent[];
}

export const ComponentNameMap: Record<string, string> = {
  dataProfile: '送审资料',
  form: '表单',
  costProfile: '造价文件',
  auditAmountSummary: '审核金额汇总',
  auditComments: '审核意见',
  settlement: '造价文件',
  budgetCompare: '概算-预算阶段造价对比',
  resultsDocument: '成果文件',
  changeAudit: '传统变更审核',
  reviewRecord: '预算复核',
  auditScore: '审核评分',
};
