import { Injectable, Logger, OnModuleInit } from '@nestjs/common';
import { PrismaService } from '../../infrastructure/database/prisma.service';

const SYSTEM_KB = {
  id: 'system-builtin-kb',
  userId: 'system',
  title: '新手引导知识库',
  description: '系统内置知识库，帮助新用户了解知习的使用方法',
  status: 'active',
};

@Injectable()
export class SystemKnowledgeBaseSeed implements OnModuleInit {
  private readonly logger = new Logger(SystemKnowledgeBaseSeed.name);

  constructor(private readonly prisma: PrismaService) {}

  async onModuleInit() {
    try {
      await this.prisma.knowledgeBase.upsert({
        where: { id: SYSTEM_KB.id },
        update: {},
        create: SYSTEM_KB,
      });
    } catch {
      this.logger.warn('Failed to seed system knowledge base');
    }
  }
}
