<?php

namespace App\Http\Controllers\Api;

use Illuminate\Http\Response;
use App\Http\Controllers\Controller;

class ApiController extends Controller
{
    /**
     * API 預設輸出格式
     *
     * @param array $data
     * @param int $code
     * @param string $message
     * @return \Illuminate\Http\JsonResponse
     */
    protected function apiResponse(array $data = [], int $code = Response::HTTP_OK, string $message = '')
    {
        if (empty($message) && isset(Response::$statusTexts[$code])) {
            $message = Response::$statusTexts[$code];
        }

        return response()->json([
            'code'    => $code,
            'message' => $message,
            'data'    => $data
        ], $code);
    }
}
