<?php

namespace Database\Seeders\Tenant;

use App\Facades\Settings;
use Illuminate\Database\Seeder;

class VehiclesInVideoSettingSeeder extends Seeder
{
    public function run(): void
    {
        collect($this->data())
            ->each(fn ($setting) => Settings::make($setting));
    }

    private function data(): array
    {
        $webhookUrl = route('tenant.notifications.vehicles-in-video.store', tenant('id'));

        $description = '<a href="https://vehiclesinvideo.com" target="_blank">Vehicles In Video</a> integration '
            . ' CURRENTLY IN DEVELOPMENT - NEEDS FULL TESTING'
            . '— sends personalised vehicle videos to customers in response to enquiries. '
            . 'Attach the <em>send-to-vehicles-in-video</em> action to any form that should trigger a video.<br/>'
            . 'When connected, Vehicles In Video will POST OAuth tokens to:<br/>'
            . 'POST ' . $webhookUrl . '<br/>'
            . '<a href="/settings/vehicles-in-video">Manage authorisation tokens →</a>';

        return [
            [
                'tab' => 'CRM',
                'section' => 'Integrations',
                'group' => 'Vehicles In Video',
                'name' => 'Enabled (In Development)',
                'config_key' => 'vehicles-in-video-enabled',
                'type' => 'boolean',
                'value' => false,
                'description' => $description,
                'superadmin' => true,
            ],
            [
                'tab' => 'CRM',
                'section' => 'Integrations',
                'group' => 'Vehicles In Video',
                'name' => 'Base URL',
                'config_key' => 'vehicles-in-video-base-url',
                'type' => 'string',
                'value' => 'https://api.dev.vehiclesinvideo.com/api/v1',
                'superadmin' => true,
            ],
            [
                'tab' => 'CRM',
                'section' => 'Integrations',
                'group' => 'Vehicles In Video',
                'name' => 'API Key',
                'config_key' => 'vehicles-in-video-api-key',
                'type' => 'secret',
                'value' => '',
                'validation_rules' => [
                    'required_if:values.vehicles-in-video-enabled,true',
                ],
                'superadmin' => true,
            ],
            [
                'tab' => 'CRM',
                'section' => 'Integrations',
                'group' => 'Vehicles In Video',
                'name' => 'Client ID',
                'config_key' => 'vehicles-in-video-client-id',
                'type' => 'string',
                'value' => '',
                'validation_rules' => [
                    'required_if:values.vehicles-in-video-enabled,true',
                ],
                'superadmin' => true,
            ],
            [
                'tab' => 'CRM',
                'section' => 'Integrations',
                'group' => 'Vehicles In Video',
                'name' => 'Notification recipients',
                'config_key' => 'vehicles-in-video-notification-recipients',
                'type' => 'string',
                'value' => '',
                'description' => 'Comma-separated email addresses notified when a video is not found '
                    . 'or the refresh token is expiring.',
                'superadmin' => true,
            ],
        ];
    }
}
