"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MongooseSupportUserRepository = void 0;
const SupportUserModel_js_1 = require("../models/SupportUserModel.js");
class MongooseSupportUserRepository {
    async findById(id) {
        const doc = await SupportUserModel_js_1.SupportUserModel.findById(id).lean();
        return doc ? this.mapDocument(doc) : null;
    }
    async findByTelegramUserId(telegramUserId) {
        const doc = await SupportUserModel_js_1.SupportUserModel.findOne({ telegramUserId }).lean();
        return doc ? this.mapDocument(doc) : null;
    }
    async findByChatId(chatId) {
        const doc = await SupportUserModel_js_1.SupportUserModel.findOne({ chatId }).lean();
        return doc ? this.mapDocument(doc) : null;
    }
    async create(input) {
        const doc = await SupportUserModel_js_1.SupportUserModel.create(input);
        return this.mapDocument(doc.toObject());
    }
    async update(id, input) {
        const doc = await SupportUserModel_js_1.SupportUserModel.findByIdAndUpdate(id, input, { new: true }).lean();
        return doc ? this.mapDocument(doc) : null;
    }
    mapDocument(doc) {
        return {
            id: doc._id.toString(),
            telegramUserId: doc.telegramUserId,
            chatId: doc.chatId,
            username: doc.username,
            firstName: doc.firstName,
            lastName: doc.lastName,
            language: doc.language,
            createdAt: doc.createdAt,
            updatedAt: doc.updatedAt
        };
    }
}
exports.MongooseSupportUserRepository = MongooseSupportUserRepository;
