<?php
/**
 * Pi Engine (http://piengine.org)
 *
 * @link            http://code.piengine.org for the Pi Engine source repository
 * @copyright       Copyright (c) Pi Engine http://piengine.org
 * @license         http://piengine.org/license.txt BSD 3-Clause License
 */

namespace Pi\Authentication;

use Laminas\Authentication\Result as BaseResult;

/**
 * Authentication result
 *
 * @author Taiwen Jiang <taiwenjiang@tsinghua.org.cn>
 */
class Result extends BaseResult
{
    /**
     * Profile data returned by authentication result
     *
     * @var array
     */
    protected $data = [];

    /**
     * Sets the result code, identity, failure messages and success data
     *
     * @param int|array $code
     * @param mixed     $identity
     * @param array     $messages
     * @param array     $data
     */
    public function __construct(
        $code,
        $identity = '',
        array $messages = [],
        array $data = []
    ) {
        if (is_array($code)) {
            extract($code);
        }
        $this->code     = (int)$code;
        $this->identity = $identity;
        $this->messages = $messages;
        $this->setData($data);
    }

    /**
     * Set result data
     *
     * @param array $data
     *
     * @return self
     */
    public function setData($data)
    {
        $this->data = (array)$data;

        return $this;
    }

    /**
     * Returns the result data
     *
     * @param string|null $column
     *
     * @return bool|mixed
     */
    public function getData($column = null)
    {
        if (null === $column) {
            $return = $this->data;
        } else {
            $return = isset($this->data[$column])
                ? $this->data[$column] : null;
        }

        return $return;
    }

    /**
     * Set result code
     *
     * @param int $code
     *
     * @return $this
     */
    public function setCode($code)
    {
        $this->code = (int)$code;

        return $this;
    }

    /**
     * Set result message
     *
     * @param string $message
     *
     * @return $this
     */
    public function setMessage($message)
    {
        $this->message = $message;

        return $this;
    }
}
