using JobsMedical.Web.Data; using JobsMedical.Web.Models; using JobsMedical.Web.Services; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.EntityFrameworkCore; namespace JobsMedical.Web.Pages.Shifts; public class DetailsModel : PageModel { private readonly AppDbContext _db; private readonly InterestService _interest; public DetailsModel(AppDbContext db, InterestService interest) { _db = db; _interest = interest; } public Shift? Shift { get; private set; } public List MoreAtFacility { get; private set; } = new(); // Set after the visitor taps "interested" — reveals the facility contact (handoff model). public bool ShowContact { get; private set; } public bool Saved { get; private set; } public bool Reported { get; private set; } public async Task OnGetAsync(int id) { await LoadAsync(id); if (Shift is null) return NotFound(); Reported = Request.Query["reported"] == "1"; await _interest.LogAsync(InterestEventType.View, id); // behavioral signal for recommendations return Page(); } public async Task OnPostInterestAsync(int id) { await LoadAsync(id); if (Shift is null) return NotFound(); await _interest.LogAsync(InterestEventType.Apply, id); ShowContact = true; // MVP handoff: reveal contact. Records an Application once auth lands. return Page(); } public async Task OnPostSaveAsync(int id) { await LoadAsync(id); if (Shift is null) return NotFound(); await _interest.LogAsync(InterestEventType.Save, id); Saved = true; return Page(); } public async Task OnPostDismissAsync(int id) { await _interest.LogAsync(InterestEventType.Dismiss, id); return RedirectToPage("/Shifts/Index"); // not interested → back to the list } private async Task LoadAsync(int id) { Shift = await _db.Shifts .Include(s => s.Facility).ThenInclude(f => f.City) .Include(s => s.Role) .FirstOrDefaultAsync(s => s.Id == id); if (Shift is not null) { var today = DateOnly.FromDateTime(DateTime.UtcNow); MoreAtFacility = await _db.Shifts .Include(s => s.Facility).ThenInclude(f => f.City) .Include(s => s.Role) .Where(s => s.FacilityId == Shift.FacilityId && s.Id != id && s.Status == ShiftStatus.Open && s.Date >= today) .OrderBy(s => s.Date).Take(3).ToListAsync(); } } }