package cz.muni.fi.pa165.soccermanager.mapper;

import cz.muni.fi.pa165.soccermanager.dto.PlayerDto;
import cz.muni.fi.pa165.soccermanager.dto.request.CreatePlayerRequest;
import cz.muni.fi.pa165.soccermanager.dto.request.UpdatePlayerDto;
import cz.muni.fi.pa165.soccermanager.factory.PlayerFactory;
import cz.muni.fi.pa165.soccermanager.entity.Player;
import cz.muni.fi.pa165.soccermanager.entity.Team;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingTarget;

import java.util.List;

@Mapper(uses = PlayerFactory.class)
public interface PlayerMapper {

    PlayerDto map(Player source);

    @Mapping(target = "team", ignore = true)
    @Mapping(target = "id", ignore = true)
    Player map(CreatePlayerRequest source);

    List<PlayerDto> map(List<Player> source);

    @Mapping(target = "id", ignore = true)
    void mapOnUpdate(@MappingTarget Player target, UpdatePlayerDto source);

    default Long map(Team team) {
        return team == null ? null : team.getId();
    }
}
