package com.seer.teach.mall.app.good.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.seer.teach.mall.entity.GoodsSpecificationEntity;
import com.seer.teach.mall.request.GoodsSpecificationQueryReq;
import com.seer.teach.mall.response.GoodsSpecificationResp;
import com.seer.teach.mall.mapper.GoodsSpecificationMapper;
import com.seer.teach.mall.convert.GoodsSpecificationConvert;
import com.seer.teach.mall.app.good.service.IAppGoodsSpecificationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.util.List;

/**
 * 微信商城商品规格服务实现类
 */
@Slf4j
@Service
public class AppGoodsSpecificationServiceImpl extends ServiceImpl<GoodsSpecificationMapper, GoodsSpecificationEntity> implements IAppGoodsSpecificationService {

    /**
     * 根据商品ID查询商品规格
     * @param params
     * @return
     */
    @Override
    public List<GoodsSpecificationResp> getGoodsSpecification(GoodsSpecificationQueryReq params) {
        // 查询与给定商品ID匹配的所有商品规格实体
        List<GoodsSpecificationEntity> list = list(new LambdaQueryWrapper<GoodsSpecificationEntity>()
                .eq(GoodsSpecificationEntity::getGoodsId, params.getId()));
        // 将查询到的商品规格实体列表转换为响应对象列表
        return GoodsSpecificationConvert.INSTANCE.list(list);
    }
}
