# -*- coding:utf-8 -*-
"""
@author: yq
@time: 2023/12/29
@desc: 
"""
import pydantic
from pydantic import BaseModel


class BaseResponse(BaseModel):
    data: object = pydantic.Field(None, description="request id")
    code: int = pydantic.Field(200, description="HTTP status code")
    msg: str = pydantic.Field("success", description="HTTP status message")
    success: bool = pydantic.Field(True, description="success status")

    class Config:
        schema_extra = {
            "example": {
                "data": None,
                "code": 200,
                "msg": "success",
                "success": True
            }
        }

    @staticmethod
    def ofSuccess(data: object):
        return BaseResponse(data=data, code=200, msg="success", success=True)

    @staticmethod
    def ofFailure(msg: str = "error"):
        return BaseResponse(data=None, code=500, msg=msg, success=False)
