<?php

namespace Lucent\Record;


class File
{

    function __construct(
        public readonly string $originalName,
        public readonly string $mime,
        public readonly string $path,
        public readonly int    $size,
        public readonly int    $width,
        public readonly int    $height,
        public readonly string $checksum,
    )
    {
    }

    public static function fromArray(array $data): File
    {
        return new File(
            originalName: data_get($data, "originalName"),
            mime: data_get($data, "mime"),
            path: data_get($data, "path"),
            size: data_get($data, "size"),
            width: data_get($data, "width"),
            height: data_get($data, "height"),
            checksum: data_get($data, "checksum"),
        );
    }

    public function toArray(): array
    {
        return \json_decode(\json_encode($this), true);
    }
}
