<?php

namespace MintyPHP\Module\Helpdesk\Handler;

use MintyPHP\Module\Helpdesk\Service\SoftwareProductSyncService;
use MintyPHP\Service\Scheduler\Handler\ScheduledJobHandlerInterface;

class SoftwareProductSyncJobHandler implements ScheduledJobHandlerInterface
{
    public function __construct(
        private readonly SoftwareProductSyncService $syncService
    ) {
    }

    public function definition(): array
    {
        return [
            'label' => 'Software product sync',
            'description' => 'Syncs contract types with Create_SaaS_License from Business Central to local database',
            'default_enabled' => 1,
            'default_timezone' => defined('APP_TIMEZONE') ? (string) APP_TIMEZONE : 'Europe/Berlin',
            'default_schedule_type' => 'daily',
            'default_schedule_interval' => 1,
            'default_schedule_time' => '02:00',
            'default_schedule_weekdays_csv' => null,
            'default_catchup_once' => 1,
            'allowed_schedule_types' => ['daily', 'weekly'],
        ];
    }

    public function execute(?int $actorUserId): array
    {
        return $this->syncService->sync();
    }
}
