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.InputData;
import com.oguerreiro.resilient.domain.InputDataUpload;
import com.oguerreiro.resilient.domain.Organization;
import com.oguerreiro.resilient.domain.Period;
import com.oguerreiro.resilient.domain.Unit;
import com.oguerreiro.resilient.domain.Variable;
import com.oguerreiro.resilient.domain.VariableCategory;
import com.oguerreiro.resilient.domain.VariableScope;
import com.oguerreiro.resilient.service.dto.InputDataDTO;
import com.oguerreiro.resilient.service.dto.InputDataUploadDTO;
import com.oguerreiro.resilient.service.dto.OrganizationDTO;
import com.oguerreiro.resilient.service.dto.PeriodDTO;
import com.oguerreiro.resilient.service.dto.UnitDTO;
import com.oguerreiro.resilient.service.dto.VariableCategoryDTO;
import com.oguerreiro.resilient.service.dto.VariableDTO;
import com.oguerreiro.resilient.service.dto.VariableScopeDTO;

/**
 * Mapper for the entity {@link InputData} and its DTO {@link InputDataDTO}.
 */
@Mapper(componentModel = "spring")
public interface InputDataMapper extends ResilientEntityMapper<InputDataDTO, InputData> {
  @Mapping(target = "variable", source = "variable", qualifiedByName = "variableName")
  @Mapping(target = "period", source = "period", qualifiedByName = "periodName")
  @Mapping(target = "sourceUnit", source = "sourceUnit", qualifiedByName = "unitName")
  @Mapping(target = "unit", source = "unit", qualifiedByName = "unitName")
  @Mapping(target = "owner", source = "owner", qualifiedByName = "organizationName")
  @Mapping(target = "sourceInputData", source = "sourceInputData", qualifiedByName = "inputDataId")
  @Mapping(target = "sourceInputDataUpload", source = "sourceInputDataUpload", qualifiedByName = "inputDataUploadId")
  InputDataDTO toDto(InputData s);

  @Named("inputDataId")
  @BeanMapping(ignoreByDefault = true)
  @Mapping(target = "id", source = "id")
  @Mapping(target = "version", source = "version")
  InputDataDTO toDtoInputDataId(InputData inputData);

  @Named("variableScopeName")
  @BeanMapping(ignoreByDefault = true)
  @Mapping(target = "id", source = "id")
  @Mapping(target = "name", source = "name")
  @Mapping(target = "version", source = "version")
  VariableScopeDTO toDtoVariableScopeName(VariableScope variableScope);

  @Named("variableCategoryName")
  @BeanMapping(ignoreByDefault = true)
  @Mapping(target = "id", source = "id")
  @Mapping(target = "name", source = "name")
  @Mapping(target = "version", source = "version")
  VariableCategoryDTO toDtoVariableCategoryName(VariableCategory variableCategory);

  @Named("variableName")
  @BeanMapping(ignoreByDefault = true)
  @Mapping(target = "id", source = "id")
  @Mapping(target = "name", source = "name")
  @Mapping(target = "code", source = "code")
  @Mapping(target = "variableScope", source = "variableScope", qualifiedByName = "variableScopeName")
  @Mapping(target = "variableCategory", source = "variableCategory", qualifiedByName = "variableCategoryName")
  @Mapping(target = "baseUnit", source = "baseUnit")
  @Mapping(target = "version", source = "version")
  VariableDTO toDtoVariableName(Variable variable);

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

  @Named("unitName")
  @BeanMapping(ignoreByDefault = true)
  @Mapping(target = "id", source = "id")
  @Mapping(target = "name", source = "name")
  @Mapping(target = "symbol", source = "symbol")
  @Mapping(target = "version", source = "version")
  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);

  @Named("inputDataUploadId")
  @BeanMapping(ignoreByDefault = true)
  @Mapping(target = "id", source = "id")
  @Mapping(target = "version", source = "version")
  InputDataUploadDTO toDtoInputDataUploadId(InputDataUpload inputDataUpload);
}
