import { apiClient } from './client';

export interface ScreenFileInfo {
  objid: string;
  savedFileName: string;
  realFileName: string;
  fileSize: number;
  fileExt: string;
  filePath: string;
  docType: string;
  docTypeName: string;
  targetObjid: string;
  parentTargetObjid?: string;
  writer: string;
  regdate: string;
  status: string;
}

export interface ScreenComponentFilesResponse {
  success: boolean;
  componentFiles: { [componentId: string]: ScreenFileInfo[] };
  totalFiles: number;
  componentCount: number;
}

export interface ComponentFilesResponse {
  success: boolean;
  files: ScreenFileInfo[];
  componentId: string;
  screenId: string;
}

export const ScreenFileAPI = {
  /**
   * 화면의 모든 컴포넌트별 파일 정보 조회
   */
  async getScreenComponentFiles(screenId: number): Promise<ScreenComponentFilesResponse> {
    const response = await apiClient.get(`/screen-files/screens/${screenId}/components/files`);
    return response.data;
  },

  /**
   * 특정 컴포넌트의 파일 목록 조회
   */
  async getComponentFiles(screenId: number, componentId: string): Promise<ComponentFilesResponse> {
    const response = await apiClient.get(`/screen-files/screens/${screenId}/components/${componentId}/files`);
    return response.data;
  }
};
