package com.lesingle.edu.common.mapper;

import com.lesingle.edu.dto.response.CourseResponse;
import com.lesingle.edu.entity.CoursePackage;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

import java.util.List;

/**
 * Course Entity Mapper
 * gradeTags/domainTags 规范为 String[]，与套餐管理适用年级对齐
 */
@Mapper(componentModel = "spring")
public interface CoursePackageMapper {

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

    /**
     * Entity 转 Response
     */
    @Mapping(target = "gradeTags", expression = "java(com.lesingle.edu.common.util.JsonUtils.parseStringArray(entity.getGradeTags()))")
    @Mapping(target = "domainTags", expression = "java(com.lesingle.edu.common.util.JsonUtils.parseStringArray(entity.getDomainTags()))")
    CourseResponse toVO(CoursePackage entity);

    /**
     * Entity 列表转 Response 列表
     */
    List<CourseResponse> toVO(List<CoursePackage> entities);

    /**
     * Response 转 Entity（用于创建/更新时）
     */
    @Mapping(target = "gradeTags", expression = "java(vo.getGradeTags() != null ? com.lesingle.edu.common.util.JsonUtils.toJson(vo.getGradeTags()) : null)")
    @Mapping(target = "domainTags", expression = "java(vo.getDomainTags() != null ? com.lesingle.edu.common.util.JsonUtils.toJson(vo.getDomainTags()) : null)")
    CoursePackage toEntity(CourseResponse vo);
}
