import type { UUID } from '#application/types' import { BaseRepository } from '#application/base/baseRepository' import { CharacterHair } from '#entities/characterHair' class CharacterHairRepository extends BaseRepository { async getFirst() { try { const repository = this.getEntityManager().getRepository(CharacterHair) const result = await repository.findOne({ id: { $exists: true } }) if (result) result.setEntityManager(this.getEntityManager()) return result } catch (error: any) { this.logger.error(`Failed to get first character hair: ${error instanceof Error ? error.message : String(error)}`) return null } } async getAll(): Promise { try { const repository = this.getEntityManager().getRepository(CharacterHair) 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 character hair: ${error instanceof Error ? error.message : String(error)}`) return [] } } async getAllSelectable(populate?: any): Promise { try { const repository = this.getEntityManager().getRepository(CharacterHair) const results = await repository.find({ isSelectable: true }, { populate }) for (const result of results) result.setEntityManager(this.getEntityManager()) return results } catch (error: any) { this.logger.error(`Failed to get selectable character hair: ${error instanceof Error ? error.message : String(error)}`) return [] } } async getById(id: UUID): Promise { try { const repository = this.getEntityManager().getRepository(CharacterHair) const result = await repository.findOne({ id }) if (result) result.setEntityManager(this.getEntityManager()) return result } catch (error: any) { this.logger.error(`Failed to get character hair by ID: ${error instanceof Error ? error.message : String(error)}`) return null } } } export default CharacterHairRepository