import type { BrotliOptions, ZlibOptions } from 'node:zlib';
import type { ResolvedConfig } from 'vite';
export type Algorithm = 'brotliCompress' | 'deflate' | 'deflateRaw' | 'gzip';
export type CompressionOptions = Partial<BrotliOptions | ZlibOptions>;
export interface ViteCompressionConfig {
    /**
     * 是否在终端上输出压缩文件及其压缩比。
     * @default true
     */
    verbose?: boolean;
    /**
     * 文件最小需要达到多少才压缩，单位为字节 1kb 等于 1024 字节
     * @default 1024
     */
    threshold?: number;
    /**
     * 压缩过滤器，仅压缩满足 正则表达式 或 方法返回true 的文件
     * @default /\.(js|mjs|json|css|html)$/i
     */
    filter?: RegExp | ((file: string) => boolean);
    /**
     * 是否禁用压缩
     * @default false
     */
    disable?: boolean;
    /**
     * 压缩算法
     * @default gzip
     */
    algorithm?: Algorithm;
    /**
     * 压缩后的文件格式
     * @default .gz
     */
    ext?: string;
    /**
     * 压缩配置
     */
    compressionOptions?: CompressionOptions;
    /**
     * 压缩后是否删除对应的源文件
     * @default false
     */
    deleteOriginFile?: boolean;
    /**
     * 自定义项目根目录 (源代码的根路径,非打包后的代码的根路径)
     */
    root?: string;
    /**
     * 自定义需要打包上传的目录 (打包生成的代码的目录(可以是相对于源代码根路径的相对路径如(dist),也可以是绝对路径))
     */
    outDir?: string;
    /**
     * 压缩完成后的回调函数
     */
    success?: (config: ViteCompressionConfig, resolvedConfig?: ResolvedConfig | null) => void;
}
export type CompressionInfo = {
    /** 压缩后文件大小 */
    size: number;
    /** 源文件大小 */
    oldSize: number;
    /**压缩后的完整路径 */
    fullPath: string;
};
/**
 * 部署模式
 */
export type DeployMode = 'build-zip-upload' | 'git-pull-run';
/**
 * Git 拉取部署进度步骤
 */
export type GitDeployStep = 'auth' | 'pull' | 'install' | 'build' | 'stop' | 'start' | 'finish';
/**
 * Git 拉取部署进度状态
 */
export type GitDeployProgressStatus = 'running' | 'success' | 'failed' | 'info';
/**
 * 鉴权失败原因
 */
export type AuthFailureReason = 
/** 项目标识未加入白名单 */
'project_not_whitelisted'
/** 当前项目下未授权该密钥对 */
 | 'key_pair_not_whitelisted'
/** 当前授权记录未配置公钥 */
 | 'public_key_missing'
/** 签名校验失败 */
 | 'signature_verification_failed';
export type ViteAutoDeployConfig = {
    /**
     * 上传地址
     */
    uploadUrl?: string;
    /**
     * 部署模式
     * @default build-zip-upload
     */
    deployMode?: DeployMode;
    /**
     * Git 拉取部署使用的 WebSocket 连接地址
     * 说明：该值会直接作为 `io()` 的第一个参数
     * 例如：`wss://api-meeting2.qyzhjy.com/upload/code/git-deploy`
     */
    websocketUrl?: string;
    /**
     * Git 拉取部署使用的 Socket.IO 握手路径
     * 说明：该值会直接作为 `io()` 的 `path` 选项
     * 例如：`/deploy/socket.io`
     */
    websocketPath?: string;
    /**
     * 项目唯一标识符 (如果多个项目都是用的同上传地址时，服务端可用此字段区分是哪一个项目)
     */
    projectKey?: string;
    /**
     * 压缩后文件名称，注意不包含后缀名
     * @default vite-auto-deploy
     */
    zipName?: string;
    /**
     * 上传完成后,是否保留压缩包到本地
     * @default false
     */
    saveLocalZip?: boolean;
    /**
     * 公私匙保存的目录，
     * @default 系统登录账号下的根目录/.vite-auto-deploy/
     */
    saveSecretKeyDirectory?: string;
    /**
     * 加密私匙的密码,
     * @default vite-auto-deploy
     */
    passphrase?: string;
    /**
     * 是否开启自动部署
     * @default true
     */
    autoDeploy?: boolean;
    /**
     * 自定义项目根目录 (源代码的根路径,非打包后的代码的根路径)
     */
    root?: string;
    /**
     * 自定义需要打包上传的目录 (打包生成的代码的目录(可以是相对于源代码根路径的相对路径如(dist),也可以是绝对路径))
     */
    outDir?: string;
    /**
     * 上传需要携带的headers
     */
    headers?: Record<string, string>;
    /**
     * 部署说明
     */
    description?: string;
    /**
     * 目标部署环境，如 production、prod_150、development
     * Git 拉取部署时会透传给服务端，用于选择对应环境配置
     */
    deployEnvironment?: string;
    /**
     * 是否检查ssl(如https自签证书) 强烈不建议设置为true
     * @default false
     */
    rejectUnauthorized?: boolean;
    /**
     * 是否重置密匙 ,注意设置为true每次打包都会重置密匙,建议重置一次后立即改为false
     * @default false
     */
    resetKey?: boolean;
    /**
     * 控制是否输出错误日志
     * @default false
     */
    debug?: boolean;
    /**
     * 部署完成后的回调函数
     */
    success?: (config: ViteAutoDeployConfig, resolvedConfig?: ResolvedConfig | null) => void;
};
export type AutoDeployPostParam = {
    /** 项目唯一标识符 */
    projectKey: string;
    /** 密匙对ID */
    keyPairId: string;
    /** 签名 */
    sign: string;
    /** 时间戳 */
    timestamp: number;
};
/**
 * Git 拉取部署请求参数
 */
export type GitDeploySocketPayload = {
    /** 部署任务 ID */
    taskId?: string;
    /** 项目唯一标识符 */
    projectKey: string;
    /** 密匙对ID */
    keyPairId: string;
    /** 签名 */
    sign: string;
    /** 时间戳 */
    timestamp: string;
    /** 目标部署环境 */
    deployEnvironment?: string;
    /** 部署说明 */
    description?: string;
};
/**
 * Git 拉取部署进度事件
 */
export type GitDeployProgressEvent = {
    /** 部署任务 ID */
    taskId?: string;
    /** 当前步骤 */
    step: GitDeployStep;
    /** 当前状态 */
    status: GitDeployProgressStatus;
    /** 当前消息 */
    message: string;
    /** 事件时间 */
    timestamp: string;
    /** 附加详情 */
    detail?: string;
};
/**
 * Git 拉取部署完成数据
 */
export type GitDeploySuccessData = {
    /** 项目标识 */
    projectKey: string;
    /** 项目名称 */
    projectName: string;
    /** 部署目录 */
    deployPath: string;
    /** 部署版本 */
    version: string;
    /** 部署时间 */
    deployTime: string;
    /** 当前提交 ID */
    commitId: string;
    /** 当前提交说明 */
    commitMessage: string;
    /** 本次更新说明列表 */
    updateSummaries: string[];
};
/**
 * Git 拉取部署结果事件
 */
export type GitDeployResultEvent = {
    /** 部署任务 ID */
    taskId?: string;
    /** 是否成功 */
    success: boolean;
    /** 结果消息 */
    message: string;
    /** 失败状态码 */
    errorCode?: number;
    /** 失败原因 */
    reason?: AuthFailureReason;
    /** 失败步骤 */
    failedStep?: GitDeployStep;
    /** 结果时间 */
    timestamp: string;
    /** 成功数据 */
    data?: GitDeploySuccessData;
};
/**
 * Git 部署恢复订阅参数
 */
export type GitDeployResumePayload = {
    /** 部署任务 ID */
    taskId: string;
};
