package com.seer.teach.mall.response;

import com.baomidou.mybatisplus.annotation.TableField;
import com.seer.teach.mall.entity.GoodsSpecificationEntity;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

@Data
@AllArgsConstructor
@NoArgsConstructor
@ToString
@Schema(description = "购物车商品分页查询响应实体类")
public class CartResp {

    @Schema(description = "购物车id")
    private Integer id;

    @Schema(description = "会员Id")
    private Integer userId;

    @Schema(description = "商品Id")
    private Integer goodsId;

    @Schema(description = "商品名称")
    private String goodsName;

    @Schema(description = "sku_id")
    private Integer skuId;

    @Schema(description = "商品价格")
    @TableField("price")
    private BigDecimal price;

    @Schema(description = "数量")
    private Integer number;

    @Schema(description = "商品图片")
    private String picUrl;

    @Schema(description = "商品属性")
    private List<Attribute> attributes;

    public void setAttributeList(List<GoodsSpecificationEntity.Attribute> attributes) {
        this.attributes = new ArrayList<>();
        for (GoodsSpecificationEntity.Attribute attribute : attributes) {
            Attribute attr = new Attribute();
            attr.setAttributeId(attribute.getAttributeId());
            attr.setAttributeName(attribute.getAttributeName());
            attr.setValueId(attribute.getValueId());
            attr.setValueName(attribute.getValueName());
            this.attributes.add(attr);
        }
    }

    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    @Schema(description = "商品属性")
    public static class Attribute {

        @Schema(name = "属性编号", example = "1")
        private Integer attributeId;

        @Schema(name = "属性名字", example = "颜色")
        private String attributeName;

        @Schema(name = "属性值编号", example = "1")
        private Integer valueId;

        @Schema(name = "属性值名字", example = "红色")
        private String valueName;

    }

}