// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
// This file is automatically generated. DO NOT EDIT

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore: Unused imports
import { Create as $Create } from "@wailsio/runtime";

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore: Unused imports
import * as time$0 from "../../../time/models.js";

export enum OS {
    /**
     * The Go zero value for the underlying type of the enum.
     */
    $zero = "",

    OSLinux = "linux",
    OSWindows = "windows",
    OSMac = "darwin",
};

/**
 * Peer 代表一个可达的网络端点 (Network Endpoint)。
 * 注意：一个物理设备 (Device) 可能通过多个网络接口广播，因此会对应多个 Peer 结构体。
 */
export class Peer {
    /**
     * ID 是物理设备的全局唯一标识 (UUID/MachineID)。
     * 具有相同 ID 的 Peer 属于同一台物理设备。
     */
    "id": string;

    /**
     * Name 是设备的主机名或用户设置的显示名称 (如 "Nite's Arch")。
     */
    "name": string;

    /**
     * Routes 记录了设备的 IP 地址和状态。
     * Key: ip, Value: *RouteState
     */
    "routes": { [_ in string]?: RouteState | null };

    /**
     * Port 是文件传输服务的监听端口。
     */
    "port": number;
    "os": OS;
    "pk": string;

    /**
     * TrustMismatch 指示该节点的公钥与本地信任列表中的公钥不匹配
     * 如果为 true，说明可能存在 ID 欺骗或密钥轮换
     */
    "trust_mismatch": boolean;

    /** Creates a new Peer instance. */
    constructor($$source: Partial<Peer> = {}) {
        if (!("id" in $$source)) {
            this["id"] = "";
        }
        if (!("name" in $$source)) {
            this["name"] = "";
        }
        if (!("routes" in $$source)) {
            this["routes"] = {};
        }
        if (!("port" in $$source)) {
            this["port"] = 0;
        }
        if (!("os" in $$source)) {
            this["os"] = OS.$zero;
        }
        if (!("pk" in $$source)) {
            this["pk"] = "";
        }
        if (!("trust_mismatch" in $$source)) {
            this["trust_mismatch"] = false;
        }

        Object.assign(this, $$source);
    }

    /**
     * Creates a new Peer instance from a string or object.
     */
    static createFrom($$source: any = {}): Peer {
        const $$createField2_0 = $$createType2;
        let $$parsedSource = typeof $$source === 'string' ? JSON.parse($$source) : $$source;
        if ("routes" in $$parsedSource) {
            $$parsedSource["routes"] = $$createField2_0($$parsedSource["routes"]);
        }
        return new Peer($$parsedSource as Partial<Peer>);
    }
}

/**
 * RouteState 记录单条路径的状态
 */
export class RouteState {
    "ip": string;

    /**
     * 该特定 IP 最后一次响应的时间
     */
    "last_seen": time$0.Time;

    /** Creates a new RouteState instance. */
    constructor($$source: Partial<RouteState> = {}) {
        if (!("ip" in $$source)) {
            this["ip"] = "";
        }
        if (!("last_seen" in $$source)) {
            this["last_seen"] = null;
        }

        Object.assign(this, $$source);
    }

    /**
     * Creates a new RouteState instance from a string or object.
     */
    static createFrom($$source: any = {}): RouteState {
        let $$parsedSource = typeof $$source === 'string' ? JSON.parse($$source) : $$source;
        return new RouteState($$parsedSource as Partial<RouteState>);
    }
}

// Private type creation functions
const $$createType0 = RouteState.createFrom;
const $$createType1 = $Create.Nullable($$createType0);
const $$createType2 = $Create.Map($Create.Any, $$createType1);
