<?php

namespace DMD\LaLigaApi\Dto;

use DMD\LaLigaApi\Entity\CustomRole;

class CustomRoleDto
{
    public int $id;
    public string $name;
    public \DateTimeImmutable $createdAt;
    public int $userId;

    public function toArray(): array
    {
        return [
            'id' => $this->id ?? '',
            'name' => $this->name ?? '',
            'userId' => $this->userId ?? '',
            'createdAt' => $this->createdAt ? $this->createdAt->format('Y-m-d H:i:s') : ''
        ];
    }

    public function fillFromArray(array $dataList): void
    {
        if (isset($dataList['id']))
        {
            $this->id = $dataList['id'];
        }
        if (!empty($dataList['name']))
        {
            $this->name = $dataList['name'];
        }
        if (!empty($dataList['createdAt']))
        {
            $this->createdAt = \DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $dataList['createdAt']);
        }
    }
    public function fillFromObject(CustomRole $customRole): void
    {
        if (!is_null($customRole->getId()))
        {
            $this->id = $customRole->getId();
        }
        if (!is_null($customRole->getName()))
        {
            $this->name = $customRole->getName();
        }
        if (!is_null($customRole->getCreatedAt()))
        {
            $this->name = $customRole->getCreatedAt();
        }
        if (!is_null(($customRole->getUser())->getId()))
        {
            $this->userId = ($customRole->getUser())->getId();
        }
    }
}