/*
*  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.product;

import cn.ysk.cashier.base.BaseMapper;
import cn.ysk.cashier.pojo.product.TbProduct;
import cn.ysk.cashier.dto.product.TbProductDto;
import cn.ysk.cashier.utils.ListUtil;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.mapstruct.Mapper;
import org.mapstruct.ReportingPolicy;

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

/**
* @website https://eladmin.vip
* @author lyf
* @date 2023-12-11
**/
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface TbProductMapper extends BaseMapper<TbProductDto, TbProduct> {
    default List<Integer> map(String value) {
        if (value == null || value.isEmpty()) {
            return null;
        }
        return ListUtil.stringChangeIntegerList(value);
    }

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