import { BaseRepository } from '#application/base/baseRepository' import { UUID } from '#application/types' import { Chat } from '#entities/chat' class ChatRepository extends BaseRepository { async getById(id: UUID): Promise { try { const repository = this.getEntityManager().getRepository(Chat) const results = await repository.find({ id }) for (const result of results) result.setEntityManager(this.getEntityManager()) return results } catch (error: any) { this.logger.error(`Failed to get chat by ID: ${error instanceof Error ? error.message : String(error)}`) return [] } } async getAll(): Promise { try { const repository = this.getEntityManager().getRepository(Chat) const results = await repository.findAll() for (const result of results) result.setEntityManager(this.getEntityManager()) return results } catch (error: any) { this.logger.error(`Failed to get all chats: ${error instanceof Error ? error.message : String(error)}`) return [] } } async getByCharacterId(characterId: UUID): Promise { try { const repository = this.getEntityManager().getRepository(Chat) const results = await repository.find({ character: characterId }) for (const result of results) result.setEntityManager(this.getEntityManager()) return results } catch (error: any) { this.logger.error(`Failed to get chats by character ID: ${error instanceof Error ? error.message : String(error)}`) return [] } } async getByMapId(mapId: UUID): Promise { try { const repository = this.getEntityManager().getRepository(Chat) const results = await repository.find({ map: mapId }) for (const result of results) result.setEntityManager(this.getEntityManager()) return results } catch (error: any) { this.logger.error(`Failed to get chats by map ID: ${error instanceof Error ? error.message : String(error)}`) return [] } } } export default ChatRepository