<?php
declare(strict_types=1);

namespace PpPhp\Core\Platform\Compatibility;

use PpPhp\Core\Platform\Compatibility\Contracts\CompatibilityAdapterInterface;

abstract class CompatibilityAdapter implements CompatibilityAdapterInterface
{
    public function __construct(
        protected readonly string $id,
        protected readonly string $legacy,
        protected readonly string $canonical,
        protected readonly string $status = 'active'
    ) {}

    public function id(): string { return $this->id; }
    public function legacy(): string { return $this->legacy; }
    public function canonical(): string { return $this->canonical; }
    public function status(): string { return $this->status; }

    public function notice(string $message = '', string $removeAfter = ''): DeprecationNotice
    {
        return new DeprecationNotice(
            $this->legacy,
            $this->canonical,
            $message !== '' ? $message : $this->legacy . ' is deprecated. Use ' . $this->canonical . ' instead.',
            $removeAfter
        );
    }

    public function toArray(): array
    {
        return [
            'id' => $this->id,
            'legacy' => $this->legacy,
            'canonical' => $this->canonical,
            'status' => $this->status,
        ];
    }
}
