package cn.reghao.tnb.content.app.mall.model.po;

import cn.reghao.jutil.jdk.web.db.BaseObject;
import cn.reghao.tnb.common.auth.UserContext;
import cn.reghao.tnb.content.api.dto.TaobaoItem;
import cn.reghao.tnb.content.app.mall.model.dto.ProductAddDto;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

/**
 * @author reghao
 * @date 2024-04-16 10:56:20
 */
@NoArgsConstructor
@Setter
@Getter
public class Product extends BaseObject<Integer> {
    private Long itemId;
    private String itemUrl;
    private String title;
    private String picUrl;
    private Double price;
    private String monthSale;
    private Integer stock;
    private Long shopId;
    private Long sellerId;

    public Product(TaobaoItem taobaoItem) {
        this.itemId = taobaoItem.getItemId();
        this.itemUrl = taobaoItem.getItemUrl();
        this.title = taobaoItem.getTitle();
        this.picUrl = taobaoItem.getPicUrl();
        this.price = taobaoItem.getPrice();
        this.monthSale = taobaoItem.getMonthSale();
        this.stock = 1000;
        this.shopId = taobaoItem.getShopId();
        this.sellerId = taobaoItem.getSellerId();
    }

    public Product(ProductAddDto productAddDto, long productId, String coverUrl) {
        this.itemId = productId;
        this.title = productAddDto.getTitle();
        this.picUrl = coverUrl;
        this.price = productAddDto.getPrice();
        this.stock = productAddDto.getAmount();
        this.sellerId = UserContext.getUserId();
    }
}
