package cn.lihongjie.coal.netDisk.mapper;

import cn.lihongjie.coal.base.mapper.BaseMapper;
import cn.lihongjie.coal.netDisk.dto.*;
import cn.lihongjie.coal.netDisk.entity.NetDiskEntity;

import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.Named;
import org.mapstruct.control.DeepClone;

import java.util.List;

@Mapper(
        componentModel = org.mapstruct.MappingConstants.ComponentModel.SPRING,
        uses = {cn.lihongjie.coal.base.mapper.CommonMapper.class, cn.lihongjie.coal.base.mapper.CommonEntityMapper.class},
        mappingControl = DeepClone.class)
public interface NetDiskMapper
        extends BaseMapper<NetDiskEntity, NetDiskDto, CreateNetDiskDto, UpdateNetDiskDto> {
    NetDiskEntity toEntity(CreateDirDto request);

    @Mappings({
        @org.mapstruct.Mapping(target = "id", ignore = true),
        @Mapping(target = "parent", ignore = true, qualifiedByName = "copyChildren"),
        @Mapping(source = "children", target = "children", ignore = false, qualifiedByName = "copyChildren" )
    })
    @Named("copyChildren")
    NetDiskEntity copyChildren(NetDiskEntity src);

    NetDiskEntity toEntity(CreateFileDto request);

    List<NetDiskDto> toDto(List<NetDiskEntity> children);

    @Mappings({
            @Mapping(source = "children", target = "children", ignore = false, qualifiedByName = "copyChildrenTree" )
    })
    @Named("copyChildrenTree")
    NetDiskTreeDto toTreeDto(NetDiskEntity root);
}
