package EPrints::KlarasConnect;

# Klaras Connect for EPrints: shared constants.
#
# Everything under EPrints::KlarasConnect:: lives in lib/plugins/ (which
# EPrints puts on @INC) but outside EPrints/Plugin/, so the plugin loader
# never mistakes a helper for a plugin. Code here must run on Perl 5.10.1
# and use core modules or modules EPrints itself ships (JSON, LWP).

use strict;
use warnings;

our $VERSION;
BEGIN { $VERSION = '0.1.1' }    # set at compile time: the constants below use it

# The control panel every installation reports to. A repository may point
# at another panel only through cfg.d (klaras_connect.panel_url), which is
# meant for development; the settings screen never offers it.
use constant PANEL_URL => 'https://panel.klaras.id';

use constant API_VERSION    => '1';
use constant PLATFORM       => 'eprints';
use constant USER_AGENT     => 'KlarasConnect-EPrints/' . $VERSION;

# URL prefixes, relative to the repository's http(s)_root.
use constant CONNECT_PREFIX => '/klaras/connect/v1';
use constant SOURCE_PREFIX  => '/klaras/source/v1';

sub version { return $VERSION }

sub panel_url
{
	my( $repo ) = @_;

	my $conf = defined $repo ? $repo->config( 'klaras_connect' ) : undef;
	my $url = ref $conf eq 'HASH' && defined $conf->{panel_url} && length $conf->{panel_url}
		? $conf->{panel_url}
		: PANEL_URL;
	$url =~ s{/+\z}{};
	return $url;
}

# True when cfg.d marks this as a development install (allows http panel,
# http base URLs). Never on by default.
sub is_development
{
	my( $repo ) = @_;

	my $conf = defined $repo ? $repo->config( 'klaras_connect' ) : undef;
	return ref $conf eq 'HASH' && $conf->{development} ? 1 : 0;
}

1;
