declare namespace Api {
  namespace Performance {
    namespace Common {
      interface PageParams {
        pageNo: number;
        pageSize: number;
      }

      interface PageResult<T> {
        total: number;
        list: T[];
      }

      type SheetStatusCode = 'draft' | 'sent' | 'confirmed' | 'rejected' | string;
      type SheetActionCode = 'send' | 'resend' | 'confirm' | 'reject' | string;
      type RemindType = 'pending_confirm' | 'pending_send';
    }

    namespace Template {
      interface ScoreCellMapping {
        actualScoreTotalCell?: string | null;
        baseScoreTotalCell?: string | null;
        extraScoreTotalCell?: string | null;
        resultDescriptionCells?: string[] | null;
        actualScoreCells?: string[] | null;
        baseScoreCells?: string[] | null;
        extraScoreCells?: string[] | null;
      }

      interface Template {
        id: string;
        templateName: string;
        fileId: string;
        fileName: string;
        employeeId?: string | null;
        employeeName?: string | null;
        employeeDeptId?: string | null;
        employeeDeptName?: string | null;
        templateYear?: number | null;
        versionNo: number;
        activeFlag: boolean;
        uploadUserId: string;
        uploadUserName: string;
        uploadTime: string;
        remark?: string | null;
        scoreCellMapping?: ScoreCellMapping | null;
      }

      type SearchParams = CommonType.RecordNullable<
        Common.PageParams & {
          templateName: string;
          employeeId: string;
          employeeName: string;
          templateYear: number;
          uploadUserName: string;
          activeFlag: boolean;
        }
      >;

      interface ScopeEmployee {
        employeeId: string;
        employeeName: string;
        employeeDeptId?: string | null;
        employeeDeptName?: string | null;
      }

      interface UploadScope {
        orgLeader: boolean;
        employeeCount: number;
        employees: ScopeEmployee[];
      }

      interface SingleUploadParams {
        employeeId: string;
        templateName: string;
        templateYear?: number | null;
        sourceFileId: string;
        sourceFileName: string;
        remark?: string | null;
      }

      interface BatchImportFileItem {
        sourceFileId: string;
        sourceFileName: string;
      }

      interface BatchImportParams {
        templateYear?: number | null;
        remark?: string | null;
        files: BatchImportFileItem[];
      }

      interface BatchImportSuccessItem {
        employeeId: string;
        employeeName: string;
        templateId: string;
        sourceFileName: string;
        sheetName?: string | null;
      }

      interface BatchImportFailureItem {
        sourceFileName: string;
        sheetName?: string | null;
        reason: string;
      }

      interface BatchImportResult {
        successCount: number;
        failureCount: number;
        successes: BatchImportSuccessItem[];
        failures: BatchImportFailureItem[];
      }
    }

    namespace Sheet {
      interface Sheet {
        id: string;
        periodMonth: string;
        employeeId: string;
        employeeName: string;
        employeeDeptId: string;
        employeeDeptName: string;
        deptOrgType: string;
        managerId: string;
        managerName: string;
        templateId: string;
        fileId?: string | null;
        fileName?: string | null;
        fileVersion: number;
        statusCode: Common.SheetStatusCode;
        statusName: string;
        signOffStatus?: string | null;
        signOffStatusName?: string | null;
        actualScoreTotal?: string | number | null;
        baseScoreTotal?: string | number | null;
        extraScoreTotal?: string | number | null;
        sentTime?: string | null;
        confirmedTime?: string | null;
        rejectedTime?: string | null;
        lastStatusReason?: string | null;
        createTime?: string | null;
        updateTime?: string | null;
      }

      type SearchParams = CommonType.RecordNullable<
        Common.PageParams & {
          employeeIds: string[];
          periodMonthRange: string[];
          employeeId: string;
          employeeName: string;
          employeeDeptId: string;
          employeeDeptName: string;
          managerId: string;
          managerName: string;
          statusCode: Common.SheetStatusCode;
          signOffStatus: string;
        }
      >;

      interface CreateParams {
        periodMonth: string;
        employeeId: string;
      }

      interface ExcelUpdateParams {
        fileId: string;
        fileName: string;
        fileVersion: number;
        actualScoreTotal: string | number;
        baseScoreTotal: string | number;
        extraScoreTotal: string | number;
      }

      interface StatusActionParams {
        reason?: string | null;
      }

      interface BatchDownloadParams {
        ids: string[];
      }

      interface ImportZipParams {
        file: File;
        periodMonth: string;
        employeeIds?: string[] | null;
      }

      interface ImportZipResult {
        workbookCount: number;
        sheetCount: number;
        successCount: number;
        skippedCount: number;
        failedCount: number;
        messages: string[];
      }

      interface SignOffParams {
        periodMonth: string;
        employeeIds?: string[] | null;
        remark?: string | null;
      }

      interface StatusDict {
        statusCode: Common.SheetStatusCode;
        statusName: string;
        sort: number;
        initialFlag: boolean;
        terminalFlag: boolean;
        allowEdit: boolean;
      }

      interface StatusTransition {
        actionCode: Common.SheetActionCode;
        actionName: string;
        fromStatusCode: Common.SheetStatusCode;
        toStatusCode: Common.SheetStatusCode;
        needReason: boolean;
      }

      interface StatusLog {
        id: string;
        sheetId: string;
        actionType: Common.SheetActionCode;
        fromStatus?: Common.SheetStatusCode | null;
        toStatus?: Common.SheetStatusCode | null;
        reason?: string | null;
        operatorUserId: string;
        operatorName: string;
        periodMonthSnapshot: string;
        employeeNameSnapshot: string;
        remark?: string | null;
        createTime: string;
      }

      interface ResponseRecord {
        id: string;
        sheetId: string;
        statusLogId: string;
        roundNo: number;
        actionType: Common.SheetActionCode;
        fromStatus: Common.SheetStatusCode;
        toStatus: Common.SheetStatusCode;
        opinion?: string | null;
        responderUserId: string;
        responderName: string;
        createTime: string;
      }

      interface MonthlyResult {
        sheetId?: string | null;
        periodMonth: string;
        employeeId: string;
        actualScoreTotal?: string | number | null;
        baseScoreTotal?: string | number | null;
        extraScoreTotal?: string | number | null;
        statusCode?: Common.SheetStatusCode | null;
      }

      interface PrefillData {
        sourceSheetId?: string | null;
        sourcePeriodMonth?: string | null;
        cellValues: Record<string, string>;
      }
    }

    namespace Team {
      interface SummaryParams {
        periodMonthStart?: string | null;
        periodMonthEnd?: string | null;
      }

      interface PendingSendUser {
        periodMonth: string;
        userId: string;
        userNickname: string;
        managerUserId?: string | null;
        managerName: string;
        sheetId?: string | null;
        statusCode?: Common.SheetStatusCode | null;
      }

      interface PendingConfirmUser {
        periodMonth: string;
        userId: string;
        userNickname: string;
        sheetId: string;
        sentTime?: string | null;
      }

      interface DeptOrgAverage {
        deptId: string;
        deptName: string;
        deptOrgType: string;
        averageScore?: string | number | null;
        confirmedCount: number;
      }

      interface Summary {
        periodMonthStart: string;
        periodMonthEnd: string;
        expectedSheetCount: number;
        pendingSendCount: number;
        pendingConfirmCount: number;
        confirmedRate: string | number;
        pendingSendUsers: PendingSendUser[];
        pendingConfirmUsers: PendingConfirmUser[];
        deptOrgAverages: DeptOrgAverage[];
      }

      interface RemindParams {
        periodMonthStart?: string | null;
        periodMonthEnd?: string | null;
        remindType: Common.RemindType;
        userIds?: string[] | null;
      }

      interface RemindResult {
        remindedCount: number;
      }
    }
  }
}
