package com.lesingle.edu.common.mapper;

import com.lesingle.edu.dto.response.ResourceItemResponse;
import com.lesingle.edu.entity.ResourceItem;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

import java.util.List;

/**
 * ResourceItem Entity Mapper
 */
@Mapper(componentModel = "spring")
public interface ResourceItemMapper {

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

    /**
     * Entity 转 Response
     * tags、library 由 Controller 单独处理（JSON 解析、关联查询）
     */
    @Mapping(target = "tags", ignore = true)
    @Mapping(target = "library", ignore = true)
    ResourceItemResponse toVO(ResourceItem entity);

    /**
     * Entity 列表转 Response 列表
     */
    List<ResourceItemResponse> toVO(List<ResourceItem> entities);

    /**
     * Response 转 Entity（用于创建/更新时）
     */
    @Mapping(target = "tags", ignore = true)
    ResourceItem toEntity(ResourceItemResponse vo);
}
