<?php

namespace onespace\tools\activeApi\models\oneaccess;

use onespace\tools\activeApi\components\clients\OneAccessClient;
use yii\helpers\ArrayHelper;

/**
 * This class is intended to be extended from within the child service,
 * though it shouldn't need to be if you just need a basic interface
 * with the method / endpoint without any extra methods.
 *
 * @property integer $id
 * @property string $guid
 * @property string $site_id
 * @property string $correlation_id
 * @property integer $access_gateway_id
 * @property integer $reader_id
 * @property integer $access_method_id
 * @property string $method_vehicle
 * @property integer $method_uid
 * @property integer $button_id
 * @property string $gateway_timestamp
 * @property string $server_timestamp
 * @property integer $success_code
 * @property string $success_message
 * @property integer $access_direction
 * @property string $access_device_serial
 * @property string $OSID
 * @property array $event_data
 * @property array $correlated_data
 * @property array $method_data
 * @property array $user_data
 *
 * @author  Gareth Palmer <gareth@one-space.co.za>
 */

class AccessEvent extends \onespace\tools\activeApi\models\BaseActiveApiModel {
    public $id;
    public $guid;
    public $site_id;
    public $correlation_id;
    public $access_gateway_id;
    public $reader_id;
    public $access_method_id;
    public $method_vehicle;
    public $method_uid;
    public $button_id;
    public $gateway_timestamp;
    public $server_timestamp;
    public $success_code;
    public $success_message;
    public $access_direction;
    public $access_device_serial;
    public $OSID;
    public $event_data;
    public $correlated_data;

    public const DIRECTION_UNKNOWN = 0;
    public const DIRECTION_ENTRY = 1;
    public const DIRECTION_EXIT = 2;
    public const DIRECTION_ASSUMED_ENTRY = 3;
    public const DIRECTION_ASSUMED_EXIT = 4;

    public function client(): OneAccessClient {
        return new OneAccessClient();
    }

    public function primaryKey(): string {
        return 'id';
    }

    public function baseEndpoints(): array {
        return [
            'v1' => 'v1/access-event',
            'v2' => 'v2/access-event',
        ];
    }

    /**
     * @inheritdoc
     */
    #[\Override]
    public function rules() {
        $parentRules = parent::rules();
        return ArrayHelper::merge($parentRules, [
            [['correlation_id', 'access_gateway_id', 'reader_id', 'access_method_id', 'method_vehicle', 'method_uid', 'button_id', 'gateway_timestamp', 'server_timestamp', 'success_code', 'success_message', 'access_direction', 'access_device_serial', 'OSID', 'event_data', 'correlated_data'], 'default', 'value' => null],
            [['id', 'access_gateway_id', 'reader_id', 'access_method_id', 'method_uid', 'button_id', 'success_code', 'access_direction'], 'integer'],
            [['gateway_timestamp', 'server_timestamp', 'event_data', 'correlated_data'], 'safe'],
            [['guid', 'site_id', 'OSID'], 'string', 'max' => 36],
            [['correlation_id'], 'string', 'max' => 20],
            [['method_vehicle'], 'string', 'max' => 350],
            [['success_message', 'access_device_serial'], 'string', 'max' => 255],
        ]);
    }
}
