<?php

namespace common\enums;

class CodeEnum
{
    const CODE_SUCCESS = 0;
    const CODE_OK = 200;
    const CODE_ERROR = 500;
    const CODE_NOT_LOGIN = 401;
    const CODE_FORBIDDEN = 403;
    const CODE_NOT_FOUND = 404;

    const STATUS_SUCCESS = 1;//成功
    const STATUS_ERROR = 2;//失败
    const STATUS_NOT_LOGIN = -1;//未登录


    public static $list = [
        self::CODE_SUCCESS => '请求成功',
        self::CODE_OK => '请求成功',
        self::CODE_ERROR => '请求失败',
        self::CODE_NOT_LOGIN => '鉴权失败',
        self::CODE_FORBIDDEN => '您没有权限',
        self::CODE_NOT_FOUND => '内容不见了',
    ];

    public static function getStatus($code)
    {
        $statusList = [
            self::CODE_SUCCESS => self::STATUS_SUCCESS,
            self::CODE_OK => self::STATUS_SUCCESS,
            self::CODE_NOT_LOGIN => self::STATUS_NOT_LOGIN,
            self::CODE_ERROR => self::STATUS_ERROR,
            self::CODE_FORBIDDEN => self::STATUS_ERROR,
            self::CODE_NOT_FOUND => self::STATUS_ERROR,
        ];
        return $statusList[$code] ? $statusList[$code] : self::STATUS_ERROR;
    }

}