package cn.reghao.tnb.content.app.mall.rpc;

import cn.reghao.tnb.content.api.dto.ItemSnapshot;
import cn.reghao.tnb.content.api.iface.MallService;
import cn.reghao.tnb.content.app.mall.db.repository.MallRepository;
import cn.reghao.tnb.content.app.mall.model.po.Product;
import cn.reghao.tnb.content.app.mall.service.CartService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Service;

/**
 * @author reghao
 * @date 2024-12-04 11:37:41
 */
@Slf4j
@DubboService
@Service
public class MallServiceImpl implements MallService {
    private final MallRepository mallRepository;
    private final CartService cartService;

    public MallServiceImpl(MallRepository mallRepository,CartService cartService) {
        this.mallRepository = mallRepository;
        this.cartService = cartService;
    }

    public void updateCancelOrder(long productId, int amount) {
        mallRepository.updateCancelOrder(productId, amount);
        log.info("cancel order");
    }

    public double getProductPrice(long itemId) {
        Product product = mallRepository.getProduct(itemId);
        return product.getPrice();
    }

    public void deleteCartItem(long userId, long productId) {
        cartService.deleteCartItem(userId, productId);
    }

    public ItemSnapshot getItemSnapshot(long orderId) {
        return mallRepository.getItemSnapshot(orderId);
    }

    public long getSellerId(long itemId) {
        Product product = mallRepository.getProduct(itemId);
        return product.getSellerId();
    }
}
