package com.seer.teach.mall.convert;

import com.seer.teach.common.enums.GoodsAttributeScopeEnum;
import com.seer.teach.mall.entity.GoodsAttributeEntity;
import com.seer.teach.mall.request.GoodsAttributeReq;
import com.seer.teach.mall.response.GoodsAttributeResq;
import org.mapstruct.Mapper;
import org.mapstruct.ValueMapping;
import org.mapstruct.factory.Mappers;

import java.util.List;

@Mapper
public interface GoodsAttributeConvert {

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


    GoodsAttributeEntity convertOne(GoodsAttributeReq req);

    List<GoodsAttributeResq> convertList(List<GoodsAttributeEntity> entityList);

    GoodsAttributeResq convertOne(GoodsAttributeEntity entity);
    
    /**
     * Integer转GoodsAttributeScopeEnum
     * @param scope
     * @return
     */
    @ValueMapping(source = "1", target = "PLATFORM")
    @ValueMapping(source = "2", target = "MERCHANT")
    default GoodsAttributeScopeEnum integerToScopeEnum(Integer scope) {
        return GoodsAttributeScopeEnum.fromCode(scope);
    }
    
    /**
     * GoodsAttributeScopeEnum转Integer
     * @param scopeEnum
     * @return
     */
    default Integer scopeEnumToInteger(GoodsAttributeScopeEnum scopeEnum) {
        return scopeEnum != null ? scopeEnum.getCode() : null;
    }
}