using JobsMedical.Web.Models; using JobsMedical.Web.Services.Scraping; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; namespace JobsMedical.Web.Pages.Admin; [Authorize(Roles = "Admin")] public class SettingsModel : PageModel { private readonly SettingsService _settings; public SettingsModel(SettingsService settings) => _settings = settings; [BindProperty] public IngestionMode Mode { get; set; } [BindProperty] public int AutoPublishMinConfidence { get; set; } [BindProperty] public bool AiEnabled { get; set; } [BindProperty] public string? AiEndpoint { get; set; } [BindProperty] public string? AiApiKey { get; set; } [BindProperty] public string? AiModel { get; set; } [BindProperty] public string AiSystemPrompt { get; set; } = ""; [BindProperty] public bool AiAutoApprove { get; set; } // Channel scraping sources [BindProperty] public bool AutoIngestEnabled { get; set; } [BindProperty] public int IngestIntervalMinutes { get; set; } = 30; [BindProperty] public bool TelegramEnabled { get; set; } [BindProperty] public string? TelegramChannels { get; set; } [BindProperty] public bool BaleEnabled { get; set; } [BindProperty] public string? BaleBotToken { get; set; } [BindProperty] public bool DivarEnabled { get; set; } [BindProperty] public string? DivarCity { get; set; } [BindProperty] public string? DivarQueries { get; set; } [BindProperty] public bool MedjobsEnabled { get; set; } [BindProperty] public int MedjobsMaxAds { get; set; } = 40; [BindProperty] public bool SmsEnabled { get; set; } [BindProperty] public string? SmsApiKey { get; set; } [BindProperty] public string? SmsTemplate { get; set; } [BindProperty] public string? SmsSender { get; set; } [BindProperty] public string? NeshanMapKey { get; set; } [BindProperty] public bool PushEnabled { get; set; } [BindProperty] public string? VapidPublicKey { get; set; } [BindProperty] public string? VapidPrivateKey { get; set; } [BindProperty] public string? VapidSubject { get; set; } [TempData] public string? Saved { get; set; } public async Task OnGetAsync() { var s = await _settings.GetAsync(); Mode = s.Mode; AutoPublishMinConfidence = s.AutoPublishMinConfidence; AiEnabled = s.AiEnabled; AiEndpoint = s.AiEndpoint; AiApiKey = s.AiApiKey; AiModel = s.AiModel; AiSystemPrompt = s.AiSystemPrompt; AiAutoApprove = s.AiAutoApprove; AutoIngestEnabled = s.AutoIngestEnabled; IngestIntervalMinutes = s.IngestIntervalMinutes; TelegramEnabled = s.TelegramEnabled; TelegramChannels = s.TelegramChannels; BaleEnabled = s.BaleEnabled; BaleBotToken = s.BaleBotToken; DivarEnabled = s.DivarEnabled; DivarCity = s.DivarCity; DivarQueries = s.DivarQueries; MedjobsEnabled = s.MedjobsEnabled; MedjobsMaxAds = s.MedjobsMaxAds; SmsEnabled = s.SmsEnabled; SmsApiKey = s.SmsApiKey; SmsTemplate = s.SmsTemplate; SmsSender = s.SmsSender; NeshanMapKey = s.NeshanMapKey; PushEnabled = s.PushEnabled; VapidPublicKey = s.VapidPublicKey; VapidPrivateKey = s.VapidPrivateKey; VapidSubject = s.VapidSubject; } public async Task OnPostAsync() { await _settings.SaveAsync(new AppSetting { Mode = Mode, AutoPublishMinConfidence = AutoPublishMinConfidence, AiEnabled = AiEnabled, AiEndpoint = AiEndpoint, AiApiKey = AiApiKey, AiModel = AiModel, AiSystemPrompt = AiSystemPrompt, AiAutoApprove = AiAutoApprove, AutoIngestEnabled = AutoIngestEnabled, IngestIntervalMinutes = IngestIntervalMinutes, TelegramEnabled = TelegramEnabled, TelegramChannels = TelegramChannels, BaleEnabled = BaleEnabled, BaleBotToken = BaleBotToken, DivarEnabled = DivarEnabled, DivarCity = DivarCity, DivarQueries = DivarQueries, MedjobsEnabled = MedjobsEnabled, MedjobsMaxAds = MedjobsMaxAds, SmsEnabled = SmsEnabled, SmsApiKey = SmsApiKey, SmsTemplate = SmsTemplate, SmsSender = SmsSender, NeshanMapKey = NeshanMapKey, PushEnabled = PushEnabled, VapidPublicKey = VapidPublicKey, VapidPrivateKey = VapidPrivateKey, VapidSubject = VapidSubject, }); Saved = "تنظیمات ذخیره شد."; return RedirectToPage(); } }