<?php
/**
 * Settings checkout field model.
 *
 * @package northmill-online-shared
 */

declare(strict_types=1);

namespace Northmill_Online_Shared\Modules\Admin\Pages\Page\Admin_Sync_Settings\Models\Properties;

use Northmill_Online_Shared\Abstracts\Data_Model;

defined( 'ABSPATH' ) || exit;

/**
 * Class Settings_Checkout_Field_Model
 *
 * @used Northmill Catering Theme
 */
class Settings_Checkout_Field_Model extends Data_Model {
	/**
	 * Checkout field id.
	 *
	 * @var string
	 */
	public string $Id;

	/**
	 * Checkout field title.
	 *
	 * @var string
	 */
	public string $Title;

	/**
	 * Checkout field type.
	 *
	 * @var string
	 */
	public string $Type;

	/**
	 * Whether the field is required in frontend.
	 *
	 * @var bool
	 */
	public bool $Required;

	/**
	 * Field priority in the checkout form.
	 * This is used to determine the order of the fields.
	 *
	 * @var int
	 */
	public int $Priority;

	/**
	 * Whether the field can be edited after the order is placed.
	 *
	 * @var bool
	 */
	public bool $PostOrderEdit;

	/**
	 * Created time.
	 *
	 * @var string
	 */
	public string $CreatedTime;

	/**
	 * Last updated time.
	 *
	 * @var string
	 */
	public string $LastUpdatedTime;

	/**
	 * Get a php type of the field.
	 *
	 * @return string
	 */
	public function get_type(): string {
		if ( 'Text' === $this->Type ) {
			return 'text';
		} elseif ( 'TextMax8' === $this->Type ) {
			return 'text_max_8';
		} elseif ( 'Textarea' === $this->Type ) {
			return 'textarea';
		} elseif ( 'Number' === $this->Type ) {
			return 'number';
		} elseif ( 'Checkbox' === $this->Type ) {
			return 'checkbox';
		}

		return 'none';
	}
}
