package com.seer.teach.mall.response;

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 java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

@Data
public class OrderSettlementRespVO {

    @Schema(name = "购物项数组")
    private List<Item> items;

    @Schema(name ="商品原价（总），单位：分")
    private BigDecimal totalPrice;

    @Schema(name ="收件地址")
    private Address address;

    @Schema(name ="购买总数量")
    private Integer totalCount;



    @Data
    public static class Item {
        @Schema(name ="商品的名称")
        private String name;

        @Schema(name ="商品的单价")
        private int count;

        @Schema(name ="价格，单位：分")
        private BigDecimal price;

        @Schema(name ="图片地址")
        private String picUrl;

        private int skuId;
        @Schema(name ="商品id")
        private int goodsId;

        /**
         * 属性数组，JSON 格式，[{"valueId": 6, "valueName": "二代", "attributeId": 3, "attributeName": "版本"}, {"valueId": 5, "valueName": "Y50", "attributeId": 2, "attributeName": "型号"}]
         */
        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);
            }

        }
    }


    @Schema(description ="地址信息")
    @Data
    public static class Address {

        @Schema(name ="编号")
        private Long id;

        @Schema(name ="收件人名称")
        private String name;

        @Schema(name ="手机号")
        private String mobile;

        @Schema(name ="地区编号")
        private Long areaId;

        @Schema(name ="地区名字")
        private String areaName;

        @Schema(name ="详细地址")
        private String detailAddress;

        @Schema(name ="是否默认收件地址")
        private Boolean defaultStatus;

    }



    @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;

    }

}