package com.persagy.proxy.adm.request;

import cn.hutool.core.collection.CollUtil;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;

/**
 * ADM 通用创建返回结果
 * @author Charlie Yu
 * @date 2021-08-16
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class AdmCreateResponse extends AdmResponse {
    private final static String SUCCESS = "success";
    private final static String FAILURE = "failure";
    /** 错误数据主从对象 1 主对象  2 从对象 */
    private String errorType;
    /**
     * 查询到的数据列表
     */
    private List<?> entityList;

    public AdmCreateResponse(String result, String message, Long total, Long count, Integer pageNumber, Integer pageSize, List<?> content, String floorId, String zoneType, List<?> entityList, String errorType) {
        super(result, message, total, count, pageNumber, pageSize, content, floorId, zoneType);
        this.entityList = entityList;
        this.errorType = errorType;
    }
    public static AdmCreateResponse failure(String message) {
        return new AdmCreateResponse(FAILURE, message, null, null, null, null, null, null, null, null, null);
    }
    public static AdmCreateResponse failure(String message,String errorType) {
        return new AdmCreateResponse(FAILURE, message,null, null, null, null, null, null, null, new ArrayList<>(), errorType);
    }
    public static AdmCreateResponse success() {
        return new AdmCreateResponse(SUCCESS, "", 0L,null, 1, 500, null,null,null,null,null);
    }
    public static AdmCreateResponse success(String message) {
        return new AdmCreateResponse(SUCCESS, message, 0L,null, 1, 500, null,null,null,null,null);
    }
    public static AdmCreateResponse success(List<?> content) {
        return new AdmCreateResponse(SUCCESS, "", CollUtil.isEmpty(content) ? 0L :content.size()*1L,null, 1, 50,null ,null,null,CollUtil.isEmpty(content) ? new ArrayList(1): content,null);
    }
}