"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.parse = exports.crawl = void 0;
const lib_1 = require("../lib");
const crawl = (word) => {
    return (0, lib_1.request)({
        protocol: 'https',
        hostname: 'sozluk.gov.tr',
        path: `/gts?ara=${encodeURIComponent(word)}`,
        headers: {
            'content-type': 'text/json',
        },
    });
};
exports.crawl = crawl;
const parse = (json) => {
    const response = JSON.parse(json);
    if (!Array.isArray(response) || ('error' in response && response.error)) {
        return {
            definitions: [],
            exists: false,
        };
    }
    const [wordInfo] = response;
    const definitions = wordInfo.anlamlarListe.map((entry) => entry.anlam.replace('►', '').trim());
    return {
        definitions,
        exists: definitions.length > 0,
    };
};
exports.parse = parse;
