using PetCompanion.Models; using PetCompanion.Repositories; namespace PetCompanion.Services { public class PetSkillService { private readonly PetSkillRepository _petSkillRepository; private readonly PetRepository _petRepository; public PetSkillService(PetSkillRepository petSkillRepository, PetRepository petRepository) { _petSkillRepository = petSkillRepository; _petRepository = petRepository; } public async Task> GetPetSkills(string petId, string userId) { var pet = _petRepository.GetPetById(petId, userId); if (pet == null) throw new Exception("Pet not found"); return await _petSkillRepository.GetPetSkills(petId); } public async Task AllocateSkillPoint(string petId, string userId, int skillId) { var pet = _petRepository.GetPetById(petId, userId); if (pet == null) throw new Exception("Pet not found"); if (pet.SkillPoints <= 0) throw new Exception("No skill points available"); var skills = await _petSkillRepository.GetPetSkills(petId); var existingSkill = skills.FirstOrDefault(s => s.SkillId == skillId); if (existingSkill != null) { if (existingSkill.CurrentTier == SkillTier.III) throw new Exception("Skill already at maximum tier"); existingSkill.CurrentTier++; await _petSkillRepository.SavePetSkill(existingSkill); } else { existingSkill = new PetSkill { PetId = petId, SkillId = skillId, CurrentTier = SkillTier.I }; await _petSkillRepository.SavePetSkill(existingSkill); } pet.SkillPoints--; _petRepository.UpdatePet(pet); return existingSkill; } } }