<?php
/**
 * Google Sign-in Module
 *
 * @package GoogleSignIn
 */

namespace GoogleSignIn;

use WP_PowerSuite\Core\AbstractModule;
use WP_PowerSuite\OAuth\SocialSignInModuleTrait;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

require_once __DIR__ . '/Config.php';
require_once __DIR__ . '/OidcProfile.php';
require_once __DIR__ . '/Provider.php';
require_once __DIR__ . '/AvatarDisplay.php';

class Module extends AbstractModule {

	use SocialSignInModuleTrait;

	private const MODULE_ID = 'google-sign-in';

	private ?Provider $provider = null;

	public function getId(): string {
		return self::MODULE_ID;
	}

	public function getName(): string {
		return __( 'Google Sign-in', 'wp-powersuite' );
	}

	public function getVersion(): string {
		return '1.1.0';
	}

	public function getDescription(): string {
		return __( 'Sign in with Google—simple for visitors, optional auto-registration for new users.', 'wp-powersuite' );
	}

	public function getContext(): string|array {
		return 'both';
	}

	protected function registerHooks(): void {
		$this->provider = new Provider( $this->moduleSettings() );
		$s              = $this->provider->getSettings();
		if ( $s['client_id'] === '' || $s['client_secret'] === '' ) {
			return;
		}

		$this->bootSocialSignInModule( ! empty( $s['woo_login'] ) );
		AvatarDisplay::register();
	}

	protected function getSocialProviderSlug(): string {
		return 'google';
	}

	protected function getSocialProvider(): object {
		return $this->provider ?? new Provider( $this->moduleSettings() );
	}

	protected function getSocialLegacyShortcodeTag(): string {
		return 'google_sign_in';
	}

	protected function getSocialProviderSettings(): array {
		return ( $this->provider instanceof Provider ) ? $this->provider->getSettings() : [];
	}
}
