using Liber_Incantamentum.Application.DTOs.Mage; using Liber_Incantamentum.Application.DTOs.Spell; using Liber_Incantamentum.Application.Interfaces.Generals; using Liber_Incantamentum.Application.Interfaces.Mappings; using Liber_Incantamentum.Application.Interfaces.Validations; using Liber_Incantamentum.Domain.Repositories; namespace Liber_Incantamentum.Application.Services.Generals { public class SpellService : ISpellService { private IValidator _validator; private ISpellRepository _spellRepository; private IMapper _mapper; public SpellService(IValidator validator, ISpellRepository spellRepository, IMapper mapper) { _mapper = mapper; _validator = validator; _spellRepository = spellRepository; } public async Task AddSpellAsync(SpellDtoCreate dto) { _validator.ValidateSpellDtoCreate(dto); return await _spellRepository.AddSpellAsync(_mapper.MapSpellDtoCreateToSpellEntity(dto)); } public async Task DeleteSpellAsync(Guid id) { _validator.ValidateGuid(id); return await _spellRepository.DeleteSpellAsync(id); } public async Task?> GetAllSpellAsync(SpellDtoFilter filter) { _validator.ValidateSpellDtoFilter(filter); return _mapper.MapSpellEntityCollectionToSpellDtoCollection(await _spellRepository.GetAllSpellAsync(_mapper.MapSpellDtoFilterToSpellFilter(filter))); } public async Task GetSpellByIdAsync(Guid id) { _validator.ValidateGuid(id); return _mapper.mapSpellEntityToSpellDto(await _spellRepository.GetSpellByIdAsync(id)); } public Task UpdateSpellAsync(SpellDtoUpdate dto) { _validator.ValidateSpellDtoUpdate(dto); return _spellRepository.UpdateSpellAsync(_mapper.MapSpellDtoUpdateToSpellEntity(dto)); } } }