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 = "PtVO", description = "盘头库存分析视图")
public class PtVO {
    private static final long serialVersionUID = 1L;
    @ApiModelProperty("TOP排名")
    private List<TopVO> tops;
    @ApiModelProperty("使用情况")
    private List<Usage> usages;
    @ApiModelProperty("库存情况")
    private List<Stock> stocks;


    public PtVO() {
        this.tops = new ArrayList<>();
        this.usages = new ArrayList<>();
        this.stocks = new ArrayList<>();
    }

    @Data
    @ApiModel("库存情况")
    public static class Stock {
        @ApiModelProperty("纱种名称")
        private String name;
        @ApiModelProperty("入库数量")
        private Integer in;
        @ApiModelProperty("出库数量")
        private Integer out;
        @ApiModelProperty("最大库存量")
        private Integer max;
        @ApiModelProperty("最小库存量")
        private Integer min;
        @ApiModelProperty("平均库存量")
        private BigDecimal avg;
        @ApiModelProperty("当前库存")
        private Integer curr;
        @ApiModelProperty(value = "当前库存明细")
        private List<PtStockVO> calc;

        public Stock() {
            this.curr = 0;
            this.in = 0;
            this.out = 0;
            this.max = 0;
            this.min = 999999999;
            this.avg = BigDecimal.ZERO;
            this.calc = new ArrayList<>();
        }

        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 Usage {
        @ApiModelProperty("最大使用量")
        private Integer max;
        @ApiModelProperty("使用率")
        private BigDecimal rate;
        @ApiModelProperty("时间")
        private LocalDate date;
        @ApiModelProperty("纱种明细")
        private List<YarnTypeDetail> details;

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


    }

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