<?php

namespace SugarCalendarBookings\Integrations\Outlook;

use SugarCalendarBookings\Options;

/**
 * Outlook meeting title/agenda templates and smart-tag picker options.
 *
 * Single source of truth for the meeting title + agenda templates used when
 * building Graph event payloads. Also exposes the grouped tag-picker config
 * used by the admin settings UI.
 *
 * @since 1.5.0
 */
class OutlookSmartTagPicker {

	/**
	 * Default meeting title template with smart-tag placeholders.
	 *
	 * @since 1.5.0
	 *
	 * @var string
	 */
	public const DEFAULT_TITLE_TEMPLATE = '{service_name} with {customer_full_name}';

	/**
	 * Default meeting agenda template (HTML) with smart-tag placeholders.
	 *
	 * @since 1.5.0
	 *
	 * @var string
	 */
	public const DEFAULT_AGENDA_TEMPLATE = "<p>{service_name}, {service_duration}</p>\n<p>Booked by {customer_full_name} ({customer_email})</p>\n<p>With {employee_full_name}</p>\n<p>{appointment_online_location_url}</p>\n<p>Booked via {site_name}</p>";

	/**
	 * Plugin options accessor.
	 *
	 * @since 1.5.0
	 *
	 * @var Options
	 */
	private Options $options;

	/**
	 * Constructor.
	 *
	 * @since 1.5.0
	 *
	 * @param Options $options Plugin options accessor.
	 */
	public function __construct( Options $options ) {

		$this->options = $options;
	}

	/**
	 * Get the saved meeting title template, or the default when unset.
	 *
	 * @since 1.5.0
	 *
	 * @return string
	 */
	public function get_title_template(): string {

		return (string) $this->options->get(
			'integrations.outlook.meeting_title',
			self::DEFAULT_TITLE_TEMPLATE
		);
	}

	/**
	 * Get the saved meeting agenda template, or the default when unset.
	 *
	 * @since 1.5.0
	 *
	 * @return string
	 */
	public function get_agenda_template(): string {

		return (string) $this->options->get(
			'integrations.outlook.meeting_agenda',
			self::DEFAULT_AGENDA_TEMPLATE
		);
	}

	/**
	 * Grouped smart-tag picker options for the title/agenda inputs.
	 *
	 * @since 1.5.0
	 *
	 * @return array
	 */
	public function get_options(): array {

		return [
			[
				'label' => esc_html__( 'Appointment', 'sugar-calendar-bookings-scheduling-appointments-lite' ),
				'tags'  => [
					[
						'value' => 'start_date',
						'label' => esc_html__( 'Start Date', 'sugar-calendar-bookings-scheduling-appointments-lite' ),
					],
					[
						'value' => 'start_time',
						'label' => esc_html__( 'Start Time', 'sugar-calendar-bookings-scheduling-appointments-lite' ),
					],
					[
						'value' => 'end_time',
						'label' => esc_html__( 'End Time', 'sugar-calendar-bookings-scheduling-appointments-lite' ),
					],
					[
						'value' => 'appointment_code',
						'label' => esc_html__( 'Appointment Code', 'sugar-calendar-bookings-scheduling-appointments-lite' ),
					],
					[
						'value' => 'appointment_online_location_url',
						'label' => esc_html__( 'Online Location URL', 'sugar-calendar-bookings-scheduling-appointments-lite' ),
					],
				],
			],
			[
				'label' => esc_html__( 'Service', 'sugar-calendar-bookings-scheduling-appointments-lite' ),
				'tags'  => [
					[
						'value' => 'service_name',
						'label' => esc_html__( 'Service Name', 'sugar-calendar-bookings-scheduling-appointments-lite' ),
					],
					[
						'value' => 'service_duration',
						'label' => esc_html__( 'Service Duration', 'sugar-calendar-bookings-scheduling-appointments-lite' ),
					],
				],
			],
			[
				'label' => esc_html__( 'Customer', 'sugar-calendar-bookings-scheduling-appointments-lite' ),
				'tags'  => [
					[
						'value' => 'customer_full_name',
						'label' => esc_html__( 'Customer Full Name', 'sugar-calendar-bookings-scheduling-appointments-lite' ),
					],
					[
						'value' => 'customer_email',
						'label' => esc_html__( 'Customer Email', 'sugar-calendar-bookings-scheduling-appointments-lite' ),
					],
				],
			],
			[
				'label' => esc_html__( 'Employee', 'sugar-calendar-bookings-scheduling-appointments-lite' ),
				'tags'  => [
					[
						'value' => 'employee_full_name',
						'label' => esc_html__( 'Employee Full Name', 'sugar-calendar-bookings-scheduling-appointments-lite' ),
					],
				],
			],
			[
				'label' => esc_html__( 'General', 'sugar-calendar-bookings-scheduling-appointments-lite' ),
				'tags'  => [
					[
						'value' => 'site_name',
						'label' => esc_html__( 'Site Name', 'sugar-calendar-bookings-scheduling-appointments-lite' ),
					],
				],
			],
		];
	}
}
