import type { ParsedNode } from './ss.js';

export function parseTrojan(uri: string): ParsedNode {
  const url = new URL(uri);
  const name = decodeURIComponent(url.hash.slice(1));
  const server = url.hostname;
  const port = parseInt(url.port, 10);
  const password = url.username;
  const params = url.searchParams;
  const sni = params.get('sni') || server;

  const surgeLine = `${name} = trojan, ${server}, ${port}, password=${password}, tls=true, sni=${sni}, skip-cert-verify=false`;

  return { name, type: 'trojan', server, port, surgeLine };
}
