@page "/design/external-systems/create" @page "/design/external-systems/{Id:int}/edit" @using ZB.MOM.WW.ScadaBridge.Security @using ZB.MOM.WW.ScadaBridge.Commons.Entities.ExternalSystems @using ZB.MOM.WW.ScadaBridge.Commons.Interfaces.Repositories @attribute [Authorize(Policy = AuthorizationPolicies.RequireDesign)] @inject IExternalSystemRepository ExternalSystemRepository @inject NavigationManager NavigationManager

@(Id.HasValue ? "Edit External System" : "Add External System")

@* Drill-in: deep-link into the central Audit Log pre-filtered to this external system's outbound API events. Audit rows record the target by external-system name, so we filter on Target. *@ @if (Id.HasValue && !string.IsNullOrWhiteSpace(_name)) { Recent audit activity }
@if (_loading) { } else {
0 = use gateway default
@if (_formError != null) {
@_formError
}
}
@code { [Parameter] public int? Id { get; set; } private bool _loading = true; private string _name = "", _endpointUrl = "", _authType = "ApiKey"; private string? _authConfig; private int _maxRetries = 3; private int _retryDelaySeconds = 5; private int _timeoutSeconds; private string? _formError; private ExternalSystemDefinition? _existing; // Per-AuthType placeholder that hints at the expected JSON shape for AuthConfig. private string _authConfigPlaceholder => _authType switch { "ApiKey" => "{\"key\":\"xyz\"}", "BasicAuth" => "{\"username\":\"u\",\"password\":\"p\"}", _ => "{}" }; protected override async Task OnInitializedAsync() { if (Id.HasValue) { try { _existing = await ExternalSystemRepository.GetExternalSystemByIdAsync(Id.Value); if (_existing != null) { _name = _existing.Name; _endpointUrl = _existing.EndpointUrl; _authType = _existing.AuthType; _authConfig = _existing.AuthConfiguration; _maxRetries = _existing.MaxRetries; _retryDelaySeconds = (int)_existing.RetryDelay.TotalSeconds; _timeoutSeconds = _existing.TimeoutSeconds; } } catch (Exception ex) { _formError = ex.Message; } } _loading = false; } private async Task Save() { _formError = null; if (string.IsNullOrWhiteSpace(_name) || string.IsNullOrWhiteSpace(_endpointUrl)) { _formError = "Name and URL required."; return; } try { if (_existing != null) { _existing.Name = _name.Trim(); _existing.EndpointUrl = _endpointUrl.Trim(); _existing.AuthType = _authType; _existing.AuthConfiguration = _authConfig?.Trim(); _existing.MaxRetries = _maxRetries; _existing.RetryDelay = TimeSpan.FromSeconds(_retryDelaySeconds); _existing.TimeoutSeconds = _timeoutSeconds; await ExternalSystemRepository.UpdateExternalSystemAsync(_existing); } else { var es = new ExternalSystemDefinition(_name.Trim(), _endpointUrl.Trim(), _authType) { AuthConfiguration = _authConfig?.Trim(), MaxRetries = _maxRetries, RetryDelay = TimeSpan.FromSeconds(_retryDelaySeconds), TimeoutSeconds = _timeoutSeconds }; await ExternalSystemRepository.AddExternalSystemAsync(es); } await ExternalSystemRepository.SaveChangesAsync(); NavigationManager.NavigateTo("/design/external-systems"); } catch (Exception ex) { _formError = ex.Message; } } private void GoBack() => NavigationManager.NavigateTo("/design/external-systems"); }