package com.ylx.giftCard.domain.vo;

import cn.hutool.core.util.ObjectUtil;
import com.ylx.giftCard.domain.GiftCard;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.math.BigDecimal;

/**
 * 礼品卡视图对象(Value Object)类
 * 用于封装礼品卡相关的数据，提供前端展示使用
 */
@Data
public class GiftCardVO {

    @ApiModelProperty("礼品卡ID")
    private Long id;

    @ApiModelProperty("礼品卡名称")
    private String name;

    @ApiModelProperty("礼品卡金额")
    private BigDecimal amount;

    @ApiModelProperty("礼品卡图片URL")
    private String imageUrl;

    @ApiModelProperty("销售数量")
    private Integer sales;

    @ApiModelProperty("库存数量")
    private Integer stock;

    @ApiModelProperty("售罄状态")
    private Boolean isSoldOut;

    /**
     * 构造函数，用于将实体对象转换为视图对象
     *
     * @param entity 礼品卡实体对象
     */
    public GiftCardVO(GiftCard entity) {
        this.id = entity.getId();
        this.name = entity.getName();
        this.amount = entity.getAmount();
        this.imageUrl = entity.getImageUrl();
        this.sales = entity.getSales();
        this.stock = entity.getStock();
        // 判断库存是否为null或小于等于0，若是则标记为售罄
        this.isSoldOut = ObjectUtil.isNull(entity.getStock()) || entity.getStock() <= 0;
    }
}
