const BUG_INTAKE_URL = process.env.BUG_INTAKE_URL?.replace(/\/+$/, "") || "https://seawork-bug-intake.sg.seaverse.dev";
export async function handleListMyIssues(msg, deps) {
    const { logger } = deps;
    const email = msg.email?.trim();
    const clientId = msg.clientId?.trim();
    if (!email && !clientId) {
        return {
            type: "list_my_issues_response",
            requestId: msg.requestId,
            ok: false,
            error: "missing_identity",
        };
    }
    const params = new URLSearchParams();
    if (email)
        params.set("email", email);
    if (clientId)
        params.set("clientId", clientId);
    if (msg.limit)
        params.set("limit", String(msg.limit));
    try {
        const res = await fetch(BUG_INTAKE_URL + "/my-issues?" + params.toString(), {
            method: "GET",
            headers: { accept: "application/json" },
        });
        if (!res.ok) {
            const text = await res.text().catch(() => "");
            logger.error({ status: res.status, text }, "bug-intake my-issues rejected");
            return {
                type: "list_my_issues_response",
                requestId: msg.requestId,
                ok: false,
                error: "intake_error_" + res.status,
            };
        }
        const body = (await res.json());
        if (!body.ok) {
            return {
                type: "list_my_issues_response",
                requestId: msg.requestId,
                ok: false,
                error: body.error ?? "intake_error",
            };
        }
        return {
            type: "list_my_issues_response",
            requestId: msg.requestId,
            ok: true,
            issues: body.issues ?? [],
        };
    }
    catch (err) {
        logger.error({ err, url: BUG_INTAKE_URL }, "bug-intake my-issues fetch failed");
        return {
            type: "list_my_issues_response",
            requestId: msg.requestId,
            ok: false,
            error: err.message || "intake_unreachable",
        };
    }
}
//# sourceMappingURL=list-my-issues-handler.js.map