<?php


namespace customerapi\models\available;


use common\helpers\AppDateTimeHelper;
use common\models\Event;
use common\models\EventRegistration;
use common\models\EventType;
use common\models\Room;
use common\models\Trainer;
use yii\base\Model;

class EventAvailable extends Model
{

    public $id;
    public $start;
    public $end;
    public $seat_count;
    public $created_at;
    public $updated_at;
    public $deleted_at;
    public $active;
    public $eventType;
    public $trainer;
    public $room;
    public $eventRegistrations;

    public $registrationCount;
    public $hasFreeSeats;

    /**
     * @param $event /common/models/Event
     */
    public static function fromEvent($event)
    {
        $available = new EventAvailable();
        $available->id = $event->id;
        $available->start = $event->start;
        $available->end = $event->end;
        $available->seat_count = $event->seat_count;
        $available->created_at = $event->created_at;
        $available->updated_at = AppDateTimeHelper::convertMySqlDatetimeToPhpInteger($event->updated_at);
        $available->deleted_at = AppDateTimeHelper::convertMySqlDatetimeToPhpInteger($event->deleted_at);
        $available->active = $event->active;

        return $available;
    }


    function fields()
    {
        $fields = [
            "id" => "id",
            "start" => "start",
            "end" => "end",
            "deleted_at" => "deleted_at",
            "seat_count" => "seat_count",
            "active" => "active",
            "reservationCount" => "registrationCount",
            "hasFreeSeats" => "hasFreeSeats",
        ];
        $fields['trainer'] = 'trainer';
        $fields['eventType'] = 'eventType';
        $fields['room'] = 'room';
        $fields['registrations'] = 'eventRegistrations';
        return $fields;
    }


    function extraFields()
    {
        $extra = parent::extraFields();
        $extra[] = 'trainer';
        return $extra;
    }

}
