import { Injectable } from "@nestjs/common"; import { PrismaService } from "../prisma/prisma.service.js"; // K-2/K-4 角色間關係:同作品角色互損、拆台、護短、吃醋等化學反應的資料來源。 // 有向邊:characterId 對 otherCharacterId 的觀感,兩邊可以各自設定、不必對稱。 @Injectable() export class CharacterRelationshipService { constructor(private readonly prisma: PrismaService) {} async set(characterId: string, otherCharacterId: string, affinity: number, dynamic?: string) { return this.prisma.client.characterRelationship.upsert({ where: { characterId_otherCharacterId: { characterId, otherCharacterId } }, update: { affinity, dynamic }, create: { characterId, otherCharacterId, affinity, dynamic }, }); } // 未設定關係時,回傳中性值(50)——同作品角色預設不特別親近也不特別有心結。 async getAffinity(characterId: string, otherCharacterId: string): Promise { const row = await this.prisma.client.characterRelationship.findUnique({ where: { characterId_otherCharacterId: { characterId, otherCharacterId } }, }); return row?.affinity ?? 50; } }