<?php
namespace customerapi\models\dto;

use common\helpers\AppDateTimeHelper;
use yii\base\Model;

class EventRegistrationDTO extends Model
{

    public $id;
    public $id_event;
    public $id_customer;
    public $id_card;
    public $id_ticket;
    public $created_at;
    public $updated_at;
    public $canceled_at;
    public $deleted_at;

    public $event;

    function fields()
    {
        $fields = [
                'id' => 'id',
                'id_event' => 'id_event',
                'id_customer' => 'id_customer',
                'id_card' => 'id_card',
                'id_ticket' => 'id_ticket',
                'created_at' => 'created_at',
                'updated_at' => 'updated_at',
                'canceled_at' => 'canceled_at',
                'deleted_at' => 'deleted_at',
        ];
        $fields['event'] = 'event';
        return $fields;
    }


    public static function fromEventRegistration($registration){
        $dto = new EventRegistrationDTO();

        $dto->id = $registration->id;
        $dto->id_event = $registration->id_event;
        $dto->id_customer = $registration->id_customer;
        $dto->id_card = $registration->id_card;
        $dto->id_ticket = $registration->id_ticket;
        $dto->created_at = AppDateTimeHelper::convertMySqlDatetimeToPhpInteger( $registration->created_at);
        $dto->updated_at = AppDateTimeHelper::convertMySqlDatetimeToPhpInteger($registration->updated_at);
        $dto->canceled_at =AppDateTimeHelper::convertMySqlDatetimeToPhpInteger( $registration->canceled_at);
        $dto->deleted_at = AppDateTimeHelper::convertMySqlDatetimeToPhpInteger($registration->deleted_at);

        return $dto;
    }

    public static function fromEventRegistrationWithEvent($registration,$event){
        $registrationDto = EventRegistrationDTO::fromEventRegistration($registration);
        $registrationDto->event = EventDTO::fromEventWithRelatedObjects($event);
        return $registrationDto;
    }


}
