package com.lesingle.edu.common.mapper;

import com.lesingle.edu.dto.response.GrowthRecordResponse;
import com.lesingle.edu.entity.GrowthRecord;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

import java.util.List;

/**
 * GrowthRecord Entity Mapper
 */
@Mapper(componentModel = "spring")
public interface GrowthRecordMapper {

    GrowthRecordMapper INSTANCE = Mappers.getMapper(GrowthRecordMapper.class);

    /**
     * Entity 转 Response（images 从 JSON 字符串解析为 List）
     */
    @Mapping(target = "images", expression = "java(java.util.Arrays.asList(com.lesingle.edu.common.util.JsonUtils.parseStringArray(entity.getImages())))")
    GrowthRecordResponse toVO(GrowthRecord entity);

    /**
     * Entity 列表转 Response 列表
     */
    List<GrowthRecordResponse> toVO(List<GrowthRecord> entities);

    /**
     * Response 转 Entity（images 从 List 转为 JSON 字符串）
     */
    @Mapping(target = "images", expression = "java(vo.getImages() != null ? com.lesingle.edu.common.util.JsonUtils.toJson(vo.getImages()) : null)")
    GrowthRecord toEntity(GrowthRecordResponse vo);
}
