package com.oguerreiro.resilient.service.mapper;

import org.mapstruct.BeanMapping;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Named;

import com.oguerreiro.resilient.domain.Organization;
import com.oguerreiro.resilient.domain.OrganizationType;
import com.oguerreiro.resilient.domain.User;
import com.oguerreiro.resilient.service.dto.OrganizationDTO;
import com.oguerreiro.resilient.service.dto.OrganizationTypeDTO;
import com.oguerreiro.resilient.service.dto.UserDTO;

/**
 * Mapper for the entity {@link Organization} and its DTO {@link OrganizationDTO}.
 */
@Mapper(componentModel = "spring")
public interface OrganizationMapper extends ResilientEntityMapper<OrganizationDTO, Organization> {
  @Mapping(target = "user", source = "user", qualifiedByName = "userLogin")
  @Mapping(target = "parent", source = "parent", qualifiedByName = "organizationName")
  @Mapping(target = "organizationType", source = "organizationType", qualifiedByName = "organizationTypeName")
  OrganizationDTO toDto(Organization s);

  @Named("userLogin")
  @BeanMapping(ignoreByDefault = true)
  @Mapping(target = "id", source = "id")
  @Mapping(target = "login", source = "login")
  UserDTO toDtoUserLogin(User user);

  @Named("organizationName")
  @BeanMapping(ignoreByDefault = true)
  @Mapping(target = "id", source = "id")
  @Mapping(target = "name", source = "name")
  @Mapping(target = "version", source = "version")
  OrganizationDTO toDtoOrganizationName(Organization organization);

  @Named("organizationTypeName")
  @BeanMapping(ignoreByDefault = true)
  @Mapping(target = "id", source = "id")
  @Mapping(target = "name", source = "name")
  @Mapping(target = "nature", source = "nature")
  @Mapping(target = "version", source = "version")
  OrganizationTypeDTO toDtoOrganizationTypeName(OrganizationType organizationType);
}
