<?php
namespace customerapi\models\dto;

use common\helpers\AppDateTimeHelper;
use customerapi\models\available\EventAvailable;

class EventDTO extends \yii\base\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;

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

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

        $dto->active = $event->active;

        return $dto;
    }

    public static function fromEventWithRelatedObjects($event){
        $eventDto = EventDTO::fromEvent($event);
        $eventDto->trainer = TrainerDTO::fromTrainer($event->trainer);
        $eventDto->room = RoomDTO::fromRoom($event->room);
        $eventDto->eventType = EventTypeDTO::fromEventType($event->eventType);
        return $eventDto;
    }

}
