<?php
/**
 * Matador /  REST API / JobListings Endpoint Schema
 *
 * @link        https://matadorjobs.com/
 * @since       3.8.0
 *
 * @package     Matador Jobs Board
 * @subpackage  Rest
 * @author      Matador Software LLC, Jeremy Scott, Paul Bearne
 * @copyright   (c) 2022, Matador Software, LLC
 *
 * @license     http://opensource.org/licenses/gpl-2.0.php GNU Public License
 */

namespace matador\MatadorJobs\Rest\Schema;

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

/**
 * Sync Endpoint Schema
 *
 * @since 3.8.0
 *
 * @final
 */
final class JobListings extends SchemaAbstract {

	/**
	 * Index
	 *
	 * Schema for GET calls to `/jobs/job-listings`
	 *
	 * @uses https://developer.wordpress.org/reference/functions/sanitize_text_field/
	 * @uses https://developer.wordpress.org/reference/functions/rest_sanitize_boolean/
	 *
	 * @since 3.9.0
	 *
	 * @return array
	 *
	 * @noinspection PhpArrayShapeAttributeCanBeAddedInspection
	 */
	public static function index(): array {
		return [
			's'      => [
				'description'       => __( 'Search job listings by keyword, or leave blank to retrieve all job listings', 'matador-jobs' ),
				'type'              => 'string',
				'default'           => '',
				'sanitize_callback' => 'sanitize_text_field',
			],
			'fields' => [
				'description'       => __( 'Determine which job fields should be returned with a comma separated list', 'matador-jobs' ),
				'type'              => 'string',
				'default'           => 'id,title',
				'sanitize_callback' => 'sanitize_text_field',
			],
			'limit' => [
				'description'       => __( "If description is included in the fields parameter, use this parameter to determine the length of the description returned. Accepts integer for number of characters, 'excerpt' which is 240 characters, or 'full' which is the full Description with formatting.", 'matador-jobs' ),
				'type'              => 'string',
				'default'           => null,
				'sanitize_callback' => 'sanitize_text_field',
			],
		];
	}

	/**
	 * Show
	 *
	 * Schema for GET calls to `/jobs/job-listings/(?P<id>[a-zA-Z0-9-_^/]+)`
	 *
	 * @uses https://developer.wordpress.org/reference/functions/sanitize_text_field/
	 *
	 * @since 3.9.0
	 *
	 * @return array
	 *
	 * @noinspection PhpArrayShapeAttributeCanBeAddedInspection
	 */
	public static function show(): array {
		return [
			'fields' => [
				'description'       => __( 'Determine which job fields should be returned with a comma separated list', 'matador-jobs' ),
				'type'              => 'string',
				'default'           => 'id,title',
				'sanitize_callback' => 'sanitize_text_field',
			],
			'limit' => [
				'description'       => __( "If description is included in the fields parameter, use this parameter to determine the length of the description returned. Accepts integer for number of characters, 'excerpt' which is 240 characters, or 'full' which is the full Description with formatting.", 'matador-jobs' ),
				'type'              => 'string',
				'default'           => null,
				'sanitize_callback' => 'sanitize_text_field',
			],
		];
	}

	/**
	 * Display Fields
	 *
	 * @since 3.9.0
	 *
	 * @return array
	 */
	public static function display_fields(): array {
		return [
			'include' => [
				'description'       => __( 'Determine which types of fields should be returned. Accepts all, meta, taxonomies or tax-terms' ),
				'type'              => 'string',
				'default'           => 'all',
				'sanitize_callback' => 'sanitize_text_field',
			],
		];
	}
}
