﻿using System.Data.Entity;
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.EntityFramework;

namespace RentahuntApp.Models
{
    // You can add profile data for the user by adding more properties to your ApplicationUser class, please visit http://go.microsoft.com/fwlink/?LinkID=317594 to learn more.
    public class ApplicationUser : IdentityUser
    {
        //public virtual CustomerProfileModels CustomerProfileModels { get; set; }
        //public virtual ContactInfoModels ContactInfoModels { get; set; }
        public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
        {
            // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
            var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
            // Add custom user claims here
            return userIdentity;
        }
    }

    public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
    {
        public DbSet<ContactInfoModels> ContactInfoModels { get; set; }
        public DbSet<ListingModels> ListingModels { get; set; }
        public DbSet<WeekDayBlockModels> WeekDayBlockModels { get; set; }
        public DbSet<MonthBlockModels> MonthBlockModels { get; set; }
        //public DbSet<DateRangeBlockModels> DateRangeBlockModels { get; set; }
        public DbSet<CustomerProfileModels> CustomerProfileModels { get; set; }
        public DbSet<BookingModel> BookingModel { get; set; }
        public ApplicationDbContext()
            : base("DefaultConnection", throwIfV1Schema: false)
        {
        }

        public static ApplicationDbContext Create()
        {
            return new ApplicationDbContext();
        }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            //Configure domain classes using modelBuilder here
            modelBuilder.Entity<ContactInfoModels>()
                .HasKey(c => c.UserId)
                .HasRequired(c => c.ApplicationUser)
                .WithRequiredDependent()
                .WillCascadeOnDelete(true);

            modelBuilder.Entity<CustomerProfileModels>()
                .HasKey(c => c.UserId)
                .HasRequired(c => c.ApplicationUser)
                .WithRequiredDependent()
                .WillCascadeOnDelete(true);

            base.OnModelCreating(modelBuilder);
        }
    }
}