package com.psbc.cpsp.entity;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.psbc.cpsp.entity.enums.BaseRespCodeEnum;
import com.psbc.cpsp.entity.enums.BaseRespCodeInterFace;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 智慧园区统一响应实体类
 * @param <T>
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class CpspReponse<T> {
    private String code;
    private String message;
    private T data;

    public CpspReponse(BaseRespCodeInterFace respCodeEnum, T data) {
        this.code = respCodeEnum.getCode();
        this.message = respCodeEnum.getDesc();
        this.data = data;
    }

    public CpspReponse(BaseRespCodeInterFace respCodeEnum) {
        this.code = respCodeEnum.getCode();
        this.message = respCodeEnum.getDesc();
    }

    public boolean isSuccess() {
        return BaseRespCodeEnum.SUCCESS.getCode().equals(this.getCode());
    }


    public static <T> CpspReponse<T> ok(T t) {
        return new CpspReponse<>(BaseRespCodeEnum.SUCCESS, t);
    }

    public static <T> CpspReponse<T> ok(BaseRespCodeInterFace respCodeEnum,T t) {
        return new CpspReponse<>(respCodeEnum, t);
    }

    public static CpspReponse ok() {
        return new CpspReponse(BaseRespCodeEnum.SUCCESS);
    }

    public static <T> CpspReponse<PageInfo<T>> ok(IPage<T> pageData) {
        return CpspReponse.ok(PageInfo.toPageInfo(pageData));
    }






}
