<?php
declare(strict_types=1);

namespace PpPhp\Core\Designer\Build\Contracts;

final class BuildArtifact
{
    public function __construct(
        private readonly string $id,
        private readonly string $type,
        private readonly string $path,
        private readonly string $contents,
        private readonly array $meta = []
    ) {}

    public static function create(string $id, string $type, string $path, string $contents, array $meta = []): self
    {
        return new self($id, $type, $path, $contents, $meta);
    }

    public function id(): string { return $this->id; }
    public function type(): string { return $this->type; }
    public function path(): string { return $this->path; }
    public function contents(): string { return $this->contents; }
    public function bytes(): int { return strlen($this->contents); }
    public function checksum(): string { return hash('sha256', $this->contents); }

    public function toArray(): array
    {
        return [
            'id' => $this->id,
            'type' => $this->type,
            'path' => $this->path,
            'contents' => $this->contents,
            'checksum' => $this->checksum(),
            'bytes' => $this->bytes(),
            'meta' => $this->meta,
        ];
    }
}
