<?php

namespace GriffinForms\Includes\Migration;

abstract class AbstractMigrationSource extends \GriffinForms\Format implements MigrationSourceInterface
{
    protected string $slug = '';
    protected string $label = '';

    public function __construct()
    {
        $this->setAll();
    }

    public function getSlug(): string
    {
        return $this->slug;
    }

    public function getLabel(): string
    {
        return $this->label;
    }

    public function getLogoUrl(): string
    {
        $base_path = trailingslashit($this->config->getRootPath()) . 'admin/images/migration/';
        $base_url = trailingslashit($this->config->getRootUrl()) . 'admin/images/migration/';
        $candidates = [
            $this->getSlug() . '.png',
            str_replace('-', '', $this->getSlug()) . '.png',
        ];

        foreach ($candidates as $candidate) {
            $path = $base_path . $candidate;
            if (file_exists($path)) {
                return $base_url . rawurlencode($candidate);
            }
        }

        return '';
    }

    public function getForms(): array
    {
        return [];
    }

    public function supportsSubmissions(): bool
    {
        return false;
    }

    public function importForm($source_id, array $options = []): MigrationResult
    {
        return (new MigrationResult())->addError(
            sprintf(
                /* translators: %s is the source label. */
                __('%s form migration is not implemented yet.', 'griffinforms-form-builder'),
                $this->getLabel()
            )
        );
    }

    public function importSubmissions($source_form_id, int $griffinforms_form_id, array $options = []): MigrationResult
    {
        return (new MigrationResult())->addError(
            sprintf(
                /* translators: %s is the source label. */
                __('%s submission migration is not implemented yet.', 'griffinforms-form-builder'),
                $this->getLabel()
            )
        );
    }
}
