<?php

namespace App\Utils;

class Response
{
    public static function success($data = null, $message = '操作成功')
    {
        return [
            'code' => 200,
            'message' => $message,
            'data' => $data
        ];
    }

    public static function fail($message = '操作失败', $code = 400)
    {
        return [
            'code' => $code,
            'message' => $message,
            'data' => null
        ];
    }

    public static function error($message = '服务器错误', $code = 500)
    {
        return [
            'code' => $code,
            'message' => $message,
            'data' => null
        ];
    }

    /**
     * 将数组转换为 JSON 字符串（中文不转义）
     */
    public static function json($data)
    {
        return json_encode($data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
    }
}
