package com.bio.bio_backend.domain.admin.common_code.mapper;

import com.bio.bio_backend.domain.admin.common_code.dto.CommonCodeDto;
import com.bio.bio_backend.domain.admin.common_code.dto.CreateCommonCodeRequestDto;
import com.bio.bio_backend.domain.admin.common_code.dto.CreateCommonCodeResponseDto;
import com.bio.bio_backend.domain.admin.common_code.dto.UpdateCommonCodeRequestDto;
import com.bio.bio_backend.domain.admin.common_code.entity.CommonCode;
import com.bio.bio_backend.global.annotation.IgnoreBaseEntityMapping;
import com.bio.bio_backend.global.config.GlobalMapperConfig;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;

import java.util.List;

@Mapper(config = GlobalMapperConfig.class)
public interface CommonCodeMapper {
    
    /**
     * CommonCode 엔티티를 CommonCodeDto로 변환
     */
    CommonCodeDto toCommonCodeDto(CommonCode commonCode);

    /**
     * CommonCodeDto를 CommonCode 엔티티로 변환
     */
    @Mapping(target = "commonGroupCode", ignore = true)
    CommonCode toCommonCode(CommonCodeDto commonCodeDto);
    
    /**
     * CommonCode 엔티티 리스트를 CommonCodeDto 리스트로 변환
     */
    List<CommonCodeDto> toCommonCodeDtoList(List<CommonCode> commonCodes);
    
    /**
     * CommonCodeDto를 CreateCommonCodeResponseDto로 변환
     */
    CreateCommonCodeResponseDto toCreateCommonCodeResponseDto(CommonCodeDto commonCodeDto);
    
    /**
     * CreateCommonCodeRequestDto를 CommonCodeDto로 변환
     */
    @Mapping(target = "oid", ignore = true)
    CommonCodeDto toCommonCodeDto(CreateCommonCodeRequestDto createRequestDto);
    
    /**
     * UpdateCommonCodeRequestDto를 CommonCodeDto로 변환
     */
    @Mapping(target = "oid", ignore = true)
    @Mapping(target = "code", ignore = true)
    CommonCodeDto toCommonCodeDto(UpdateCommonCodeRequestDto updateRequestDto);
    
    /**
     * CommonCodeDto의 값으로 CommonCode 엔티티를 업데이트
     */
    @IgnoreBaseEntityMapping
    @Mapping(target = "commonGroupCode", ignore = true)
    void updateCommonCodeFromDto(CommonCodeDto commonCodeDto, @org.mapstruct.MappingTarget CommonCode commonCode);
}
