import {Module, OnModuleInit} from '@nestjs/common';
import {TelegramContentWriterCompletedProcessor} from "./telegram.content.writer.completed.processor";
import {TelegramUpdates} from "./telegram.updates";
import {ManagerModule} from "../manager/manager.module";
import {PgPostService} from "../../shared/pg.post.service";
import {PublishPageService} from "../social-api/publish.page.service";
import {FacebookApi} from "../social-api/facebook.api";
import {SocialModule} from "../social-api/social.module";
import {InjectBot} from "nestjs-telegraf";
import {Context, Telegraf} from "telegraf";
import {XReaderService} from "../x-reader/x-reader.service";
import {TrendsService} from "../trends/trends.service";
import {CollectorModule} from "../collector/collector.module";
import {WriterWizard} from "./wizard/writer.wizard";
import {CommentWizard} from "./wizard/comment.wizard";
import {QuoteWizard} from "./wizard/quote.wizard";
import {XImageUploadService} from "../x-uploader/x-image.upload.service";
import {Comment2Wizard} from "./wizard/comment2.wizard";
import {SqsPostService} from "../sqs-module/sqs.post.service";


@Module({
    imports: [
        ManagerModule,
        SocialModule,
        CollectorModule,
    ],
    providers: [
        TelegramUpdates,
        TelegramContentWriterCompletedProcessor,
        FacebookApi,
        PgPostService,
        PublishPageService,
        XReaderService,
        TrendsService,
        WriterWizard,
        CommentWizard,
        QuoteWizard,
        Comment2Wizard,
        XImageUploadService,
        SqsPostService
    ],
})
export class TelegramModule implements OnModuleInit{
    constructor(@InjectBot() private readonly bot: Telegraf<Context>) {}

    async onModuleInit() {
        try {
            await this.bot.telegram.setMyCommands( [
                { command: 'start', description: 'Khởi động bot' },
                { command: 'help', description: 'Trợ giúp' },
                { command: 'trendstat', description: 'trend statistic' },
                { command: 'analyzenews', description: 'Tìm trend' },
                { command: 'ask', description: 'Hoi AI' },
                { command: 'write', description: 'Version mới, dùng 2 AI, 1 viết và 1 reviewer' },
                { command: 'write_', description: 'Version mới, dùng 2 AI, 1 viết và 1 reviewer' },
                { command: 'writecheap', description: 'Version cũ, dùng deepseek' },
                { command: 'xreader', description: 'Lấy nội dung băng api' },
                { command: 'xreader_browser', description: 'Lấy nội dung bằng trình duyệt' },
                { command: 'collectrss', description: 'Lấy nội dung' },
                { command: 'comment', description: 'Viet reply X' },
                { command: 'comen', description: '/com[en,ja,vi,ko] comment as text' },
            ]);
            console.log('✅ Đã cập nhật Menu commands thành công');
        } catch (error) {
            console.error('❌ Lỗi khi cập nhật Menu:', error);
        }
    }
}

