package com.red.circle.other.app.inner.service.activity.impl;

import com.red.circle.other.app.inner.convertor.activity.ActivityGlobalizationDescriptionInnerConvertor;
import com.red.circle.other.app.inner.service.activity.GlobalizationDescriptionClientService;
import com.red.circle.other.infra.database.rds.service.activity.ActivityGlobalizationDescriptionService;
import com.red.circle.other.inner.model.dto.activity.ActivityGlobalizationDescriptionDTO;
import java.util.List;
import java.util.Objects;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * 活动国际化语言描述 实现.
 *
 * @author pengliang on 2023/10/8
 */
@Service
@RequiredArgsConstructor
public class GlobalizationDescriptionClientServiceImpl implements
    GlobalizationDescriptionClientService {

  private final ActivityGlobalizationDescriptionService activityGlobalizationDescriptionService;
  private final ActivityGlobalizationDescriptionInnerConvertor activityGlobalizationDescriptionInnerConvertor;

  @Override
  public List<ActivityGlobalizationDescriptionDTO> listByRelationId(Long relationId) {
    return activityGlobalizationDescriptionInnerConvertor.toListActivityGlobalizationDescriptionDTO(
        activityGlobalizationDescriptionService.listByRelationId(relationId)
    );
  }

  @Override
  public void saveOrUpdate(ActivityGlobalizationDescriptionDTO dto) {

    var entity = activityGlobalizationDescriptionInnerConvertor.toActivityGlobalizationDescriptionDTO(
        dto);

    if (Objects.isNull(dto.getId())) {
      activityGlobalizationDescriptionService.save(entity);
      return;
    }

    activityGlobalizationDescriptionService.updateSelectiveById(entity);
  }

  @Override
  public void deleteById(Long id) {
    activityGlobalizationDescriptionService.removeById(id);
  }

}
