package com.crm.rely.backend.core.dto.base;


import com.crm.rely.backend.core.constant.Constants;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author houn
 */
@Data
@NoArgsConstructor
public class BaseResultWithPagerDto<T> extends BaseResultDto<T> {

    private PageDto page;

    public static <T> BaseResultWithPagerDto success(T data, PageDto page) {
        return BaseResultWithPagerDto.success(Constants.SUCCESS, data, page);
    }

    public static BaseResultWithPagerDto success(PageDto page) {
        return BaseResultWithPagerDto.success(Constants.SUCCESS, null, page);
    }

    public static <T> BaseResultWithPagerDto success(String msg, T data, PageDto page) {
        return result(Constants.SUCCESS_CODE, msg, data, page);
    }

    public static <T> BaseResultWithPagerDto error(String msg, T data, PageDto page) {
        return result(Constants.FAILED_CODE, msg, data, page);
    }

    private static <T> BaseResultWithPagerDto result(int code, String msg, T data, PageDto page) {
        return new BaseResultWithPagerDto(code, msg, data, page);

    }

    public BaseResultWithPagerDto(PageDto page) {
        super(Constants.SUCCESS_CODE, Constants.SUCCESS);
        this.page = page;
    }

    public BaseResultWithPagerDto(PageDto page, T data) {
        super(Constants.SUCCESS_CODE, Constants.SUCCESS);
        this.page = page;
        this.setData(data);
    }

    public BaseResultWithPagerDto(int code, String msg) {
        super(code, msg);
    }

    public BaseResultWithPagerDto(int code, String msg, PageDto page) {
        super(code, msg);
        this.page = page;
    }

    public BaseResultWithPagerDto(int code, String msg, PageDto page, T data) {
        super(code, msg, data);
        this.page = page;
    }

    public BaseResultWithPagerDto(int code, String msg, T data, PageDto page) {
        super(code, msg, data);
        this.page = page;
    }

}
