package org.dromara.member.exception;

import lombok.Data;
import lombok.EqualsAndHashCode;

import java.io.Serial;

/**
 * 版本相关异常
 *
 * @author pengles
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class VersionException extends RuntimeException {

    @Serial
    private static final long serialVersionUID = 1L;

    /**
     * 错误码
     */
    private Integer code;

    /**
     * 错误信息
     */
    private String message;

    public VersionException(String message) {
        super(message);
        this.message = message;
        this.code = 400;
    }

    public VersionException(Integer code, String message) {
        super(message);
        this.code = code;
        this.message = message;
    }

    public VersionException(String message, Throwable cause) {
        super(message, cause);
        this.message = message;
        this.code = 400;
    }

    /**
     * 版本不存在异常
     */
    public static VersionException versionNotFound(String version) {
        return new VersionException(5001, "版本不存在: " + version);
    }

    /**
     * 版本号重复异常
     */
    public static VersionException versionCodeDuplicate(Integer versionCode) {
        return new VersionException(5002, "版本号已存在: " + versionCode);
    }

    /**
     * 版本号无效异常
     */
    public static VersionException invalidVersionCode(Integer versionCode) {
        return new VersionException(5003, "版本号无效: " + versionCode);
    }

    /**
     * 平台不支持异常
     */
    public static VersionException unsupportedPlatform(String platform) {
        return new VersionException(5004, "不支持的平台: " + platform);
    }

    /**
     * 版本发布失败异常
     */
    public static VersionException publishFailed(String reason) {
        return new VersionException(5005, "版本发布失败: " + reason);
    }

    /**
     * 版本撤回失败异常
     */
    public static VersionException withdrawFailed(String reason) {
        return new VersionException(5006, "版本撤回失败: " + reason);
    }

    /**
     * 强制更新版本冲突异常
     */
    public static VersionException forceUpdateConflict(String version) {
        return new VersionException(5007, "强制更新版本冲突: " + version);
    }

    /**
     * 版本比较异常
     */
    public static VersionException versionCompareError(String currentVersion, String targetVersion) {
        return new VersionException(5008, "版本比较失败: " + currentVersion + " vs " + targetVersion);
    }

    /**
     * 下载链接无效异常
     */
    public static VersionException invalidDownloadUrl(String url) {
        return new VersionException(5009, "下载链接无效: " + url);
    }
}