package cn.iocoder.yudao.module.order.vo.order;

import cn.iocoder.yudao.module.order.dto.FeeGroupDto;
import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

@Data
@ApiModel("分页结果")
public final class ContainerReportOrderPageResult<T> implements Serializable {

    @ApiModelProperty(value = "数据", required = true)
    private List<T> list;

    @ApiModelProperty(value = "总量", required = true, example = "0")
    private Long total = 0L;

    @ApiModelProperty(value = "每页记录数", required = true, example = "10")
    private Long rows = 10L;

    @ApiModelProperty(value = "当前页数", required = true, example = "1")
    private Long page = 1L;

    @ApiModelProperty(value = "总页数", required = true, example = "0")
    private Long pages = 0L;

    @ApiModelProperty(value = "应收总金额货币分组列表")
    private List<FeeGroupDto> receivableTotalFeeGroupDtoList = new ArrayList<>();

    @ApiModelProperty(value = "优惠总金额货币分组列表")
    private List<FeeGroupDto> discountTotalFeeGroupDtoList = new ArrayList<>();

    @ApiModelProperty(value = "实收总金额货币分组列表")
    private List<FeeGroupDto> netReceiptsTotalFeeGroupDtoList = new ArrayList<>();

    @ApiModelProperty(value = "已收总金额货币分组列表")
    private List<FeeGroupDto> writeOffTotalFeeGroupDtoList = new ArrayList<>();

    @ApiModelProperty(value = "未收总金额货币分组列表")
    private List<FeeGroupDto> notWriteOffTotalFeeGroupDtoList = new ArrayList<>();

    @ApiModelProperty(value = "当页应收总金额货币分组列表")
    private List<FeeGroupDto> pageReceivableTotalFeeGroupDtoList = new ArrayList<>();

    @ApiModelProperty(value = "当页优惠总金额货币分组列表")
    private List<FeeGroupDto> pageDiscountTotalFeeGroupDtoList = new ArrayList<>();

    @ApiModelProperty(value = "当页实收总金额货币分组列表")
    private List<FeeGroupDto> pageNetReceiptsTotalFeeGroupDtoList = new ArrayList<>();

    @ApiModelProperty(value = "当页已收总金额货币分组列表")
    private List<FeeGroupDto> pageWriteOffTotalFeeGroupDtoList = new ArrayList<>();

    @ApiModelProperty(value = "当页未收总金额货币分组列表")
    private List<FeeGroupDto> pageNotWriteOffTotalFeeGroupDtoList = new ArrayList<>();

    public ContainerReportOrderPageResult() {
    }

    public ContainerReportOrderPageResult(List<T> list, long total) {
        this.list = list;
        this.total = total;
    }

    public ContainerReportOrderPageResult(List<T> list, long total, long rows, long page, long pages) {
        this.list = list;
        this.rows = rows;
        this.page = page;
        this.pages = pages;
        this.total = total;
    }

    public ContainerReportOrderPageResult(long total) {
        this.list = new ArrayList<>();
        this.total = total;
    }

    public static <T> ContainerReportOrderPageResult<T> empty() {
        return new ContainerReportOrderPageResult<>();
    }

    public static <T> ContainerReportOrderPageResult<T> empty(long total) {
        return new ContainerReportOrderPageResult<>(total);
    }

    /****
     * 分页转换
     * @param pager
     * @return
     */
    public static <T> ContainerReportOrderPageResult<T> of(IPage<T> pager) {
        return new ContainerReportOrderPageResult<>(pager.getRecords(), pager.getTotal(), pager.getSize(), pager.getCurrent(), pager.getPages());
    }

    /****
     * 分页转换
     * @param pager
     * @return
     */
    public static <T> ContainerReportOrderPageResult<T> of(PageInfo<T> pager) {
        return new ContainerReportOrderPageResult<>(pager.getList(), pager.getTotal(), pager.getPageSize(), pager.getPageNum(), pager.getPages());
    }
}
