/*
*  Copyright 2019-2020 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package cn.ysk.cashier.mapper.shop;

import cn.ysk.cashier.base.BaseMapper;
import cn.ysk.cashier.pojo.shop.TbShopInfo;
import cn.ysk.cashier.dto.shop.TbShopInfoDto;
import cn.ysk.cashier.utils.ListUtil;
import org.mapstruct.Mapper;
import org.mapstruct.ReportingPolicy;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.stream.Collectors;

/**
* @website https://eladmin.vip
* @author lyf
* @date 2023-11-07
**/
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface TbShopInfoMapper extends BaseMapper<TbShopInfoDto, TbShopInfo> {

    // 自定义的字符串到整数列表的转换方法
    default List<String> map(String value) {
        return ListUtil.stringChangeStringList(value);
    }

    // 如果需要从DTO转回实体，也可能需要实现反向的映射方法
    default String map(List<String> values) {
        if (!CollectionUtils.isEmpty(values)) {
            return "";
        }
        // 将整数列表转换为由逗号分隔的字符串
        return values.stream()
                .map(String::valueOf)
                .collect(Collectors.joining(","));
    }
}