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.Preferences;

public class IndexModel : PageModel
{
    private readonly AppDbContext _db;
    private readonly InterestService _interest;

    public IndexModel(AppDbContext db, InterestService interest)
    {
        _db = db;
        _interest = interest;
    }

    public List<Role> Roles { get; private set; } = new();
    public List<City> Cities { get; private set; } = new();

    [BindProperty] public int? RoleId { get; set; }
    [BindProperty] public int? CityId { get; set; }
    [BindProperty] public ShiftType? PreferredShiftType { get; set; }
    [BindProperty] public long? MinPay { get; set; }
    [BindProperty] public Gender Gender { get; set; }

    public bool Saved { get; private set; }

    // Preferences have moved onto the «پیشنهادهای ویژه شما» page (settings next to their result).
    // Keep this route working by redirecting any old link/bookmark there.
    public IActionResult OnGet() => RedirectToPage("/Recommendations/Index");

    public async Task<IActionResult> OnPostAsync()
    {
        await _interest.SavePreferencesAsync(RoleId, CityId, PreferredShiftType, MinPay, Gender);
        return RedirectToPage("/Recommendations/Index");
    }
}
