package com.jjt.inventory.vo;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;


/**
 * 白柸布库存视图
 *
 * @author ruoyi
 * @date 2024-12-30
 */
@Data
@ApiModel(value = "BpVO", description = "白柸布库存视图")
public class BpVO {
    private static final long serialVersionUID = 1L;
    @ApiModelProperty("TOP排名")
    private List<TopVO> tops;
    @ApiModelProperty("近一月库存情况-卷数")
    private List<MonthStock> rollMonthStocks;
    @ApiModelProperty("近一月库存情况-米数")
    private List<MonthStock> meterMonthStocks;
    @ApiModelProperty("近一月库存情况-重量")
    private List<MonthStock> weightMonthStocks;
    @ApiModelProperty("库存情况-卷数")
    private List<Stock> rollStocks;
    @ApiModelProperty("库存情况-米数")
    private List<Stock> meterStocks;
    @ApiModelProperty("库存情况-重量")
    private List<Stock> weightStocks;

    public BpVO() {
        this.tops = new ArrayList<>();
        this.rollMonthStocks = new ArrayList<>();
        this.meterMonthStocks = new ArrayList<>();
        this.weightMonthStocks = new ArrayList<>();
        this.rollStocks = new ArrayList<>();
        this.meterStocks = new ArrayList<>();
        this.weightStocks = new ArrayList<>();
    }

    @Data
    @ApiModel("库存情况")
    public static class Stock {
        @ApiModelProperty("纱种名称")
        private String name;
        @ApiModelProperty("米克重")
        private Integer mick;
        @ApiModelProperty("入库数量")
        private Integer in;
        @ApiModelProperty("出库数量")
        private Integer out;
        @ApiModelProperty("最大库存量")
        private Integer max;
        @ApiModelProperty("最小库存量")
        private Integer min;
        @ApiModelProperty("平均库存量")
        private BigDecimal avg;

        public Stock() {
            this.in = 0;
            this.out = 0;
            this.max = 0;
            this.min = 999999999;
            this.avg = BigDecimal.ZERO;
        }

        public void addIn(int amount) {
            this.in += amount;
        }

        public void calcAvg(int amount) {
            this.avg = avg.divide(BigDecimal.valueOf(amount), 2, RoundingMode.HALF_UP);
        }

        public void total(int amount) {
            this.avg = this.avg.add(BigDecimal.valueOf(amount));
        }

        public void addOut(int amount) {
            this.out += amount;
        }

        public void updateMax(int current) {
            this.max = Math.max(this.max, current);
        }

        public void updateMin(int current) {
            this.min = Math.min(this.min, current);
        }
    }

    @Data
    @ApiModel("近一月库存情况")
    public static class MonthStock {
        @ApiModelProperty("最大库存")
        private Integer max;
        @ApiModelProperty("最小库存")
        private Integer min;
        @ApiModelProperty("均量库存")
        private BigDecimal avg;
        @ApiModelProperty("时间")
        private LocalDate date;
        @ApiModelProperty("最大库存时-纱种明细")
        private List<YarnTypeDetail> details;
        @ApiModelProperty("最小库存时-纱种明细")
        private List<YarnTypeDetail> minDetails;

        public MonthStock() {
            this.details = new ArrayList<>();
            this.minDetails = new ArrayList<>();
        }
    }

    @Data
    @NoArgsConstructor
    @ApiModel("纱种明细")
    public static class YarnTypeDetail {
        @ApiModelProperty("纱种名称")
        private String name;
        @ApiModelProperty("米克重")
        private Integer mick;
        @ApiModelProperty("数量")
        private Integer num;
        @ApiModelProperty("纱种占比")
        private BigDecimal ratio;
    }
}
