export interface RequestResult<T = unknown> {
  data: T;
  errorCode: number;
  message?: string;
}

export type SkillIssueSeverity = 'ERROR' | 'INFO' | 'WARNING';
export type SkillVisibilityScope = 'DEPT' | 'PRIVATE' | 'PUBLIC';
export type SkillToolType = 'MCP' | 'PLUGIN' | 'WORKFLOW';

export interface SkillInfo {
  approvalPending?: boolean;
  categoryId?: number | string;
  categoryName?: string;
  created?: string;
  createdByName?: string;
  currentApprovalActionType?: string;
  currentApprovalInstanceId?: number | string;
  description?: string;
  displayName?: string;
  displayPublishStatus?: string;
  id?: number | string;
  manageable?: boolean;
  modified?: string;
  name?: string;
  packageHash?: string;
  publishStatus?: string;
  readable?: boolean;
  resources?: SkillResource[];
  skillContent?: string;
  snapshotHash?: string;
  hasToolUpdate?: boolean;
  toolBindings?: SkillToolBinding[];
  toolCount?: number;
  visibilityScope?: SkillVisibilityScope;
}

export interface SkillToolBinding {
  hitlEnabled?: boolean;
  id?: number | string;
  mcpToolCount?: number;
  mcpToolManifestHash?: string;
  resourceSummary?: {
    approvalRequired?: boolean;
    available?: boolean;
    description?: string;
    title?: string;
    toolCount?: number;
  };
  sortNo?: number;
  targetId: number | string;
  toolType: SkillToolType;
}

export interface SkillToolOption {
  approvalRequired?: boolean;
  available: boolean;
  description?: string;
  knownToolCount?: number;
  targetId: number | string;
  title: string;
  toolType: SkillToolType;
}

export interface SkillToolOptionPage {
  pageNum: number;
  pageSize: number;
  records: SkillToolOption[];
  total: number;
}

export interface SkillMcpTool {
  description?: string;
  inputSchema?: unknown;
  name: string;
  outputSchema?: unknown;
}

export interface SkillMcpToolManifest {
  manifestHash: string;
  toolCount: number;
  tools: SkillMcpTool[];
}

export interface SkillResource {
  content?: string;
  contentHash?: string;
  contentRef?: string;
  id?: number | string;
  isText?: boolean;
  kind?: string;
  mediaType?: string;
  path: string;
  size?: number;
}

export interface SkillFileNode {
  children?: SkillFileNode[];
  contentHash?: string;
  isText?: boolean;
  key: string;
  language?: string;
  mediaType?: string;
  name: string;
  path: string;
  size?: number;
  type: string;
}

export interface SkillFileContent {
  content?: string;
  contentHash?: string;
  isText?: boolean;
  language?: string;
  mediaType?: string;
  path: string;
  size?: number;
  type: string;
}

export interface SkillValidationIssue {
  code?: string;
  column?: number;
  line?: number;
  message: string;
  path?: string;
  severity: SkillIssueSeverity;
  suggestion?: string;
}

export interface SkillValidationResult {
  issues: SkillValidationIssue[];
  valid: boolean;
}

export interface SkillImportPreviewFile {
  kind: 'ASSET' | 'EXAMPLE' | 'OTHER' | 'REFERENCE' | 'SCRIPT' | 'SKILL';
  mediaType?: string;
  path: string;
  size: number;
  text: boolean;
}

export interface SkillImportPreviewItem {
  conflict: boolean;
  conflictReason?: 'NAME_UNAVAILABLE' | 'NOT_DRAFT';
  description?: string;
  files?: SkillImportPreviewFile[];
  name: string;
  overwriteAllowed?: boolean;
  packageHash?: string;
  packageId: string;
  packageRoot?: string;
}

export interface SkillImportPreview {
  expiresAt?: string;
  importToken?: string;
  issues?: SkillValidationIssue[];
  sourceName?: string;
  skills: SkillImportPreviewItem[];
}

export interface SkillImportConfirmPayload {
  categoryId?: number | string;
  conflictStrategy: 'OVERWRITE' | 'REJECT' | 'RENAME';
  importToken: string;
  renames?: Record<string, string>;
  visibilityScope: SkillVisibilityScope;
}

export interface SkillImportBatchResult {
  importToken?: string;
  message?: string;
  skills: SkillInfo[];
  success: boolean;
}

export type SkillGitCandidateStatus = 'IMPORTABLE' | 'NEEDS_ATTENTION';

export interface SkillGitCandidateIssue {
  code: string;
  message: string;
  path?: string;
}

export interface SkillGitCandidate {
  candidateId: string;
  description?: string;
  issues: SkillGitCandidateIssue[];
  name: string;
  path: string;
  resourceCount: number;
  status: SkillGitCandidateStatus;
  totalBytes: number;
}

export interface SkillGitScanResult {
  candidates: SkillGitCandidate[];
  expiresAt: string;
  repository: {
    commitSha: string;
    defaultBranch: string;
    name: string;
    url: string;
  };
  scanToken: string;
  summary: {
    discovered: number;
    importable: number;
    needsAttention: number;
  };
}

export interface SkillFileBuffer {
  content: string;
  conflict?: boolean;
  file: SkillFileContent;
  original: string;
  pendingContent?: string;
  revision: number;
  saveState: 'dirty' | 'error' | 'saved' | 'saving';
}

export interface SkillCategory {
  categoryName: string;
  children?: SkillCategory[];
  id: number | string;
  levelNo?: number;
  parentId?: number | string;
  sortNo?: number;
  status?: number;
}

export interface SkillCategoryDraft {
  categoryName: string;
  id?: number | string;
  parentId?: '' | null | number | string;
  sortNo?: number;
  status?: number;
}
