#ifndef CONVERT_MULTI_TO_ZIP64_FLAT_MODULAR_H
#define CONVERT_MULTI_TO_ZIP64_FLAT_MODULAR_H

#include <stdint.h>
#include <stddef.h>

#define MAX_PATH 4096
#define MAX_FILES 65536

// 路径信息结构体
typedef struct {
    char abs_target_zip[MAX_PATH];
    char final_zip_path[MAX_PATH];
    char tmpdir[MAX_PATH];
    char abs_tmpdir[MAX_PATH];
    char parent_dir[MAX_PATH];
    int parent_dir_set;
} PathInfo;

// 文件分流结构体
typedef struct {
    char *bigfiles[MAX_FILES];
    char *bigentry[MAX_FILES];
    int big_count;
    char *smallfiles[MAX_FILES];
    char *smallentry[MAX_FILES];
    int small_count;
    char *emptyfiles[MAX_FILES];
    char *emptyentry[MAX_FILES];
    int empty_count;
} FileSplitInfo;

// 文件信息结构体
typedef struct {
    char abs_path[MAX_PATH];
    char entry_name[MAX_PATH];
    uint64_t orig_size;
    int is_dir;
} FlatFileEntry;

// zip entry结构体
typedef struct {
    char entry_name[MAX_PATH];
    uint8_t *deflate_data;
    size_t dlen;
    uint32_t crc32;
    uint64_t orig_size;
    uint64_t offset;
    int use_zip64;
    int method;
    int is_dir;
} Entry;

// 函数声明
void prepare_paths_and_tmpdir(const char *output_zip, const char *parent_dir, PathInfo *path_info);
void add_flat_entry(FlatFileEntry **flat_entries, size_t *flat_entry_count, size_t *flat_entry_cap, const char *abs_path, const char *entry_name, uint64_t orig_size, int is_dir);
int is_tmpdir_path(const char *path);
void collect_files_flat(const char *input_path, const char *base_dir, const char *parent_dir, FlatFileEntry **flat_entries, size_t *flat_entry_count, size_t *flat_entry_cap);
void collect_all_files(int argc, char *argv[], FlatFileEntry **flat_entries, size_t *flat_entry_count, PathInfo *path_info);
void split_files(FlatFileEntry *flat_entries, size_t flat_entry_count, FileSplitInfo *split_info);
void compress_big_files(FileSplitInfo *split_info, PathInfo *path_info);
void generate_smallfile_list(FileSplitInfo *split_info, PathInfo *path_info);
void compress_small_files(PathInfo *path_info);
void parse_smalls_zip(Entry **entries, int *entry_count, PathInfo *path_info);
void parse_gz_files(Entry **entries, int *entry_count, FileSplitInfo *split_info, PathInfo *path_info);
void append_empty_entries(Entry **entries, int *entry_count, FileSplitInfo *split_info);
void assemble_zip64(Entry *entries, int entry_count, PathInfo *path_info);
void finalize_and_cleanup(PathInfo *path_info);
int parse_args(int argc, char *argv[], char **input_list_file, char **output_zip, char **parent_dir);
void load_file_list(const char *input_list_file, const char *parent_dir, FlatFileEntry **flat_entries, size_t *flat_entry_count, size_t *flat_entry_cap);

#endif // CONVERT_MULTI_TO_ZIP64_FLAT_MODULAR_H 