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

export type SkillCapabilityType = 'MCP' | 'PLUGIN_ITEM' | 'WORKFLOW';
export type SkillExportFormat = 'EASYFLOW' | 'STANDARD';
export type SkillIssueSeverity = 'ERROR' | 'INFO' | 'WARNING';

export interface SkillInfo {
  approvalPending?: boolean;
  assetCount?: number;
  bindings?: SkillCapabilityBinding[];
  capabilityCount?: number;
  capabilityHash?: string;
  categoryId?: number | string;
  categoryName?: string;
  created?: string;
  createdByName?: string;
  currentApprovalActionType?: string;
  currentApprovalInstanceId?: number | string;
  description?: string;
  displayName?: string;
  displayPublishStatus?: string;
  enabled?: boolean;
  id?: number | string;
  manageable?: boolean;
  metadataJson?: Record<string, unknown>;
  modified?: string;
  name?: string;
  packageHash?: string;
  publishStatus?: string;
  referenceCount?: number;
  resourceCount?: number;
  resources?: SkillResource[];
  scriptCount?: number;
  skillContent?: string;
  sourceType?: string;
  visibilityScope?: string;
  [key: string]: unknown;
}

export interface SkillResource {
  content?: string;
  contentHash?: string;
  contentRef?: string;
  id?: number | string;
  isText?: boolean;
  kind?: string;
  language?: string;
  mediaType?: string;
  metadataJson?: Record<string, unknown>;
  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 SkillCapabilityBinding {
  bindingKey?: string;
  capabilityType: SkillCapabilityType;
  enabled: boolean;
  executionMode?: 'ASYNC' | 'SYNC';
  hitlConfigJson?: Record<string, unknown>;
  hitlEnabled?: boolean;
  id?: number | string;
  optionsJson?: Record<string, unknown>;
  runtimeName?: string;
  resolvedToolNames?: string[];
  selectedToolNamesJson?: string[];
  selectionMode?: 'ALL' | 'SELECTED';
  sortNo?: number;
  targetLogicalRef?: string;
  targetStatus?: 'AVAILABLE' | 'NO_PERMISSION' | 'UNAVAILABLE' | 'UNRESOLVED';
  targetId?: number | string;
  targetName?: string;
  targetSummary?: string;
}

export interface SkillCapabilityCandidate {
  capabilityType: SkillCapabilityType;
  description?: string;
  logicalRef?: string;
  name: string;
  revision?: string;
  status?: string;
  targetId: number | string;
  toolNames?: string[];
}

export interface SkillCapabilityTools {
  status: string;
  targetId: number | string;
  toolNames: string[];
}

export interface SkillCapabilityReplaceResult {
  bindings: SkillCapabilityBinding[];
  capabilityHash: string;
}

export interface SkillImportPreviewItem {
  assetCount?: number;
  conflict: boolean;
  conflictReason?: 'NAME_UNAVAILABLE' | 'NOT_DRAFT';
  description?: string;
  files?: SkillImportPreviewFile[];
  name: string;
  packageHash?: string;
  packageId: string;
  packageRoot?: string;
  overwriteAllowed?: boolean;
  referenceCount?: number;
  resourceCount?: number;
  scriptCount?: number;
  suggestedName?: string;
  validationIssues?: SkillValidationIssue[];
}

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

export interface SkillCapabilityMapping {
  bindingKey: string;
  capabilityType: SkillCapabilityType;
  disabled?: boolean;
  packageRoot?: string;
  runtimeName?: string;
  status: 'RESOLVED' | 'UNRESOLVED';
  targetId?: number | string;
  targetLogicalRef?: string;
  targetName?: string;
}

export interface SkillImportPreview {
  capabilityMappings?: SkillCapabilityMapping[];
  expiresAt?: string;
  format: SkillExportFormat;
  importToken: string;
  issues?: SkillValidationIssue[];
  skills: SkillImportPreviewItem[];
}

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;
}
