using EnotaryoPH.Data;
using EnotaryoPH.Web.Common.Models;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace EnotaryoPH.Web.Pages
{
    public abstract class BaseIdentificationDocumentPageModel : PageModel
    {
        protected readonly NotaryoDBContext _notaryoDBContext;

        protected BaseIdentificationDocumentPageModel(NotaryoDBContext notaryoDBContext) => _notaryoDBContext = notaryoDBContext;

        protected void CreateIdentificationDocument(Guid user_UID)
        {
            ArgumentOutOfRangeException.ThrowIfEqual(Guid.Empty, user_UID);
            var user = _notaryoDBContext.Users.AsNoTracking().FirstOrDefault(u => u.User_UID == user_UID) ?? throw new ArgumentException("User does not exist.");
            var entity = NewIdentificationDocument.ToEntity(user.UserID);
            _notaryoDBContext.Add(entity);
            _notaryoDBContext.SaveChanges();
        }

        [BindProperty(SupportsGet = true)]
        public Guid IdentificationDocument_UID { get; set; }

        [BindProperty]
        public IdentificationDocumentModel NewIdentificationDocument { get; set; }

        [BindProperty]
        public bool UploadNewIdentification { get; set; }
    }
}