<?php
namespace boru\ai\Asset;

class Asset
{
    /** @var string|null */
    protected $id;

    /** @var string|null */
    protected $kind;

    /** @var string|null */
    protected $path;

    /** @var string|null */
    protected $filename;

    /** @var string|null */
    protected $mimeType;

    /** @var int|null */
    protected $size;

    /** @var string|null */
    protected $sha256;

    /** @var string|null */
    protected $sourceUrl;

    /** @var array */
    protected $metadata = array();

    public function id($value = null)
    {
        if ($value !== null) {
            $this->id = (string)$value;
            return $this;
        }
        return $this->id;
    }

    public function kind($value = null)
    {
        if ($value !== null) {
            $this->kind = (string)$value;
            return $this;
        }
        return $this->kind;
    }

    public function path($value = null)
    {
        if ($value !== null) {
            $this->path = (string)$value;
            return $this;
        }
        return $this->path;
    }

    public function filename($value = null)
    {
        if ($value !== null) {
            $this->filename = (string)$value;
            return $this;
        }
        return $this->filename;
    }

    public function mimeType($value = null)
    {
        if ($value !== null) {
            $this->mimeType = (string)$value;
            return $this;
        }
        return $this->mimeType;
    }

    public function size($value = null)
    {
        if ($value !== null) {
            $this->size = (int)$value;
            return $this;
        }
        return $this->size;
    }

    public function sha256($value = null)
    {
        if ($value !== null) {
            $this->sha256 = (string)$value;
            return $this;
        }
        return $this->sha256;
    }

    public function sourceUrl($value = null)
    {
        if ($value !== null) {
            $this->sourceUrl = (string)$value;
            return $this;
        }
        return $this->sourceUrl;
    }

    public function metadata($key = null, $value = null)
    {
        if ($key === null) {
            return $this->metadata;
        }
        if (is_array($key)) {
            $this->metadata = $key;
            return $this;
        }
        if (func_num_args() > 1) {
            $this->metadata[$key] = $value;
            return $this;
        }
        return isset($this->metadata[$key]) ? $this->metadata[$key] : null;
    }

    public function toArray()
    {
        return array(
            'id' => $this->id(),
            'kind' => $this->kind(),
            'path' => $this->path(),
            'filename' => $this->filename(),
            'mime_type' => $this->mimeType(),
            'size' => $this->size(),
            'sha256' => $this->sha256(),
            'source_url' => $this->sourceUrl(),
            'metadata' => $this->metadata(),
        );
    }
}
