<?php
namespace app\modules\hub\controllers\api\endpoints\session;

use yii\beutils\components\rest\Endpoint;
use app\modules\hub\essentials\Session;
use app\modules\hub\models\api\Session as Model;

class EndpointStartV1_0 extends Endpoint{

    private $session = null;
    private $model = null;

    public function __construct(){
        $this->session = new Session();
        $this->model = new Model('start'); 
    }

    protected function get(){

        // Set model data
        $this->model->attributes = \Yii::$app->rest->request->data;
        
        // Validate model
        if (!($this->model->validate())){
            \Yii::$app->rest->BAD_REQUEST();
        }

        // Create session
        $new_sid = $this->session->startSession($this->model->domain, $this->model->peer_id);

        return ["new_sid" => $new_sid];
    }

    protected function post(){
        \Yii::$app->rest->METHOD_NOT_ALLOWED();
    }

    protected function put(){
        \Yii::$app->rest->METHOD_NOT_ALLOWED();
    }

    protected function delete(){
        \Yii::$app->rest->METHOD_NOT_ALLOWED();
    }
}