<?php

namespace app\entity\admin\response\user;

use app\entity\admin\response\AdminCommonResponseEntity;
use think\response\Json;

/**
 * 零号线用户响应实体
 * 继承自 AdminCommonResponseEntity，用于零号线用户相关操作的响应
 * 此接口只需要返回成功或失败状态
 */
class ZeroUserListResponseEntity extends AdminCommonResponseEntity
{
    /**
     * 创建零号线用户操作成功响应
     * @param  null  $data
     * @param  string  $message
     * @param  int  $code
     * @return AdminCommonResponseEntity
     */
    public static function success(string $message = '获取列表成功', int $code = 200, $data = null): AdminCommonResponseEntity {
        return parent::success($message);
    }

    /**
     * 创建零号线用户操作失败响应
     * @param  string  $message
     * @param  int  $code
     * @param  null  $data
     * @return AdminCommonResponseEntity
     */
    public static function error(string $message = '获取列表失败', int $code = 400, $data = null): AdminCommonResponseEntity {
        return parent::error($message, $code);
    }

    /**
     * @param  bool  $isPage
     * @param $data
     */
    public static function response(array $data, bool $isPage=true) : Json
    {
        // if (empty($data['data'])) {
        //     return app('json')->fail(self::error()->toResponseArray());
        // }

        // 返回列表实体
        $list = parent::paginate($data['data'],$data['total'],$data['current_page'],$data['per_page']);
        return app('json')->success($list->toResponseArray());
    }

}