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.OutputData;
import com.oguerreiro.resilient.domain.Period;
import com.oguerreiro.resilient.domain.PeriodVersion;
import com.oguerreiro.resilient.domain.Unit;
import com.oguerreiro.resilient.domain.Variable;
import com.oguerreiro.resilient.service.dto.OrganizationDTO;
import com.oguerreiro.resilient.service.dto.OutputDataDTO;
import com.oguerreiro.resilient.service.dto.PeriodDTO;
import com.oguerreiro.resilient.service.dto.PeriodVersionDTO;
import com.oguerreiro.resilient.service.dto.UnitDTO;
import com.oguerreiro.resilient.service.dto.VariableDTO;

/**
 * Mapper for the entity {@link OutputData} and its DTO {@link OutputDataDTO}.
 */
@Mapper(componentModel = "spring")
public interface OutputDataMapper extends ResilientEntityMapper<OutputDataDTO, OutputData> {
  @Mapping(target = "variable", source = "variable", qualifiedByName = "variableName")
  @Mapping(target = "period", source = "period", qualifiedByName = "periodName")
  @Mapping(target = "periodVersion", source = "periodVersion", qualifiedByName = "periodVersionName")
  @Mapping(target = "baseUnit", source = "baseUnit", qualifiedByName = "unitName")
  @Mapping(target = "owner", source = "owner", qualifiedByName = "organizationName")
  OutputDataDTO toDto(OutputData s);

  @Named("variableName")
  @BeanMapping(ignoreByDefault = true)
  @Mapping(target = "id", source = "id")
  @Mapping(target = "name", source = "name")
  @Mapping(target = "code", source = "code")
  VariableDTO toDtoVariableName(Variable variable);

  @Named("periodName")
  @BeanMapping(ignoreByDefault = true)
  @Mapping(target = "id", source = "id")
  @Mapping(target = "name", source = "name")
  PeriodDTO toDtoPeriodName(Period period);

  @Named("periodVersionName")
  @BeanMapping(ignoreByDefault = true)
  @Mapping(target = "id", source = "id")
  @Mapping(target = "name", source = "name")
  PeriodVersionDTO toDtoPeriodVersionName(PeriodVersion periodVersion);

  @Named("unitName")
  @BeanMapping(ignoreByDefault = true)
  @Mapping(target = "id", source = "id")
  @Mapping(target = "name", source = "name")
  @Mapping(target = "symbol", source = "symbol")
  UnitDTO toDtoUnitName(Unit unit);

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