//------------------------------------------------------------------------------
// This is auto-generated code.
//------------------------------------------------------------------------------
// This code was generated by Entity Developer tool using EF Core template.
// Code is generated on: 24.01.2022 08:57:25
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
//------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.Common;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Internal;
using Microsoft.EntityFrameworkCore.Metadata;
using FoodsharingSiegen.Contracts.Entity;

namespace FoodsharingSiegen.Server.Data
{

    public partial class FsContext : DbContext
    {

        public FsContext() :
            base()
        {
            OnCreated();
        }

        public FsContext(DbContextOptions<FsContext> options) :
            base(options)
        {
            OnCreated();
        }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            if (!optionsBuilder.IsConfigured ||
                (!optionsBuilder.Options.Extensions.OfType<RelationalOptionsExtension>().Any(ext => !string.IsNullOrEmpty(ext.ConnectionString) || ext.Connection != null) &&
                 !optionsBuilder.Options.Extensions.Any(ext => !(ext is RelationalOptionsExtension) && !(ext is CoreOptionsExtension))))
            {
            }
            CustomizeConfiguration(ref optionsBuilder);
            base.OnConfiguring(optionsBuilder);
        }

        partial void CustomizeConfiguration(ref DbContextOptionsBuilder optionsBuilder);

        public virtual DbSet<User> Users
        {
            get;
            set;
        }

        public virtual DbSet<InteractionProcess> InteractionProcesses
        {
            get;
            set;
        }

        public virtual DbSet<Prospect> Prospects
        {
            get;
            set;
        }

        public virtual DbSet<InteractionDate> InteractionDates
        {
            get;
            set;
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);

            this.UserMapping(modelBuilder);
            this.CustomizeUserMapping(modelBuilder);

            this.InteractionProcessMapping(modelBuilder);
            this.CustomizeInteractionProcessMapping(modelBuilder);

            this.ProspectMapping(modelBuilder);
            this.CustomizeProspectMapping(modelBuilder);

            this.InteractionDateMapping(modelBuilder);
            this.CustomizeInteractionDateMapping(modelBuilder);

            RelationshipsMapping(modelBuilder);
            CustomizeMapping(ref modelBuilder);
        }

        #region User Mapping

        private void UserMapping(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<User>().ToTable(@"Users");
            modelBuilder.Entity<User>().Property(x => x.Id).HasColumnName(@"Id").IsRequired().ValueGeneratedOnAdd();
            modelBuilder.Entity<User>().Property(x => x.Mail).HasColumnName(@"Mail").IsRequired().ValueGeneratedNever();
            modelBuilder.Entity<User>().Property(x => x.Type).HasColumnName(@"Type").IsRequired().ValueGeneratedNever();
            modelBuilder.Entity<User>().Property(x => x.Verified).HasColumnName(@"Verified").IsRequired().ValueGeneratedNever();
            modelBuilder.Entity<User>().Property(x => x.Name).HasColumnName(@"Name").IsRequired().ValueGeneratedNever();
            modelBuilder.Entity<User>().Property(x => x.Created).HasColumnName(@"Created").IsRequired().ValueGeneratedNever();
            modelBuilder.Entity<User>().HasKey(@"Id");
        }

        partial void CustomizeUserMapping(ModelBuilder modelBuilder);

        #endregion

        #region InteractionProcess Mapping

        private void InteractionProcessMapping(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<InteractionProcess>().ToTable(@"InteractionProcesses");
            modelBuilder.Entity<InteractionProcess>().Property(x => x.Id).HasColumnName(@"Id").IsRequired().ValueGeneratedOnAdd();
            modelBuilder.Entity<InteractionProcess>().Property(x => x.EinAb1Id).HasColumnName(@"EinAb1Id").IsRequired().ValueGeneratedNever();
            modelBuilder.Entity<InteractionProcess>().Property(x => x.EinAb2Id).HasColumnName(@"EinAb2Id").IsRequired().ValueGeneratedNever();
            modelBuilder.Entity<InteractionProcess>().Property(x => x.EinAb3Id).HasColumnName(@"EinAb3Id").IsRequired().ValueGeneratedNever();
            modelBuilder.Entity<InteractionProcess>().Property(x => x.WelcomeId).HasColumnName(@"WelcomeId").IsRequired().ValueGeneratedNever();
            modelBuilder.Entity<InteractionProcess>().Property(x => x.VerifyId).HasColumnName(@"VerifyId").IsRequired().ValueGeneratedNever();
            modelBuilder.Entity<InteractionProcess>().Property(x => x.PassId).HasColumnName(@"PassId").IsRequired().ValueGeneratedNever();
            modelBuilder.Entity<InteractionProcess>().HasKey(@"Id");
        }

        partial void CustomizeInteractionProcessMapping(ModelBuilder modelBuilder);

        #endregion

        #region Prospect Mapping

        private void ProspectMapping(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Prospect>().ToTable(@"Prospects");
            modelBuilder.Entity<Prospect>().Property(x => x.Id).HasColumnName(@"Id").IsRequired().ValueGeneratedOnAdd();
            modelBuilder.Entity<Prospect>().Property(x => x.FsId).HasColumnName(@"FsId").IsRequired().ValueGeneratedNever();
            modelBuilder.Entity<Prospect>().Property(x => x.Name).HasColumnName(@"Name").IsRequired().ValueGeneratedNever();
            modelBuilder.Entity<Prospect>().Property(x => x.ProgressId).HasColumnName(@"ProgressId").IsRequired().ValueGeneratedNever();
            modelBuilder.Entity<Prospect>().HasKey(@"Id");
        }

        partial void CustomizeProspectMapping(ModelBuilder modelBuilder);

        #endregion

        #region InteractionDate Mapping

        private void InteractionDateMapping(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<InteractionDate>().ToTable(@"InteractionDates");
            modelBuilder.Entity<InteractionDate>().Property(x => x.Id).HasColumnName(@"Id").IsRequired().ValueGeneratedOnAdd();
            modelBuilder.Entity<InteractionDate>().Property(x => x.Date).HasColumnName(@"Date").IsRequired().ValueGeneratedNever();
            modelBuilder.Entity<InteractionDate>().Property(x => x.UserId).HasColumnName(@"UserId").ValueGeneratedNever();
            modelBuilder.Entity<InteractionDate>().HasKey(@"Id");
        }

        partial void CustomizeInteractionDateMapping(ModelBuilder modelBuilder);

        #endregion

        private void RelationshipsMapping(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<User>().HasMany(x => x.InteractionDates).WithOne(op => op.User).HasForeignKey(@"UserId").IsRequired(true);

            modelBuilder.Entity<InteractionProcess>().HasOne(x => x.EinAb1).WithOne().HasPrincipalKey(typeof(InteractionProcess), @"EinAb1Id").HasForeignKey(typeof(InteractionDate), @"Id").IsRequired(true);
            modelBuilder.Entity<InteractionProcess>().HasOne(x => x.EinAb2).WithOne().HasPrincipalKey(typeof(InteractionProcess), @"EinAb2Id").HasForeignKey(typeof(InteractionDate), @"Id").IsRequired(true);
            modelBuilder.Entity<InteractionProcess>().HasOne(x => x.EinAb3).WithOne().HasPrincipalKey(typeof(InteractionProcess), @"EinAb3Id").HasForeignKey(typeof(InteractionDate), @"Id").IsRequired(true);
            modelBuilder.Entity<InteractionProcess>().HasOne(x => x.Welcome).WithOne().HasPrincipalKey(typeof(InteractionProcess), @"WelcomeId").HasForeignKey(typeof(InteractionDate), @"Id").IsRequired(true);
            modelBuilder.Entity<InteractionProcess>().HasOne(x => x.Verify).WithOne().HasPrincipalKey(typeof(InteractionProcess), @"VerifyId").HasForeignKey(typeof(InteractionDate), @"Id").IsRequired(true);
            modelBuilder.Entity<InteractionProcess>().HasOne(x => x.Pass).WithOne().HasPrincipalKey(typeof(InteractionProcess), @"PassId").HasForeignKey(typeof(InteractionDate), @"Id").IsRequired(true);

            modelBuilder.Entity<Prospect>().HasOne(x => x.Progress).WithOne().HasPrincipalKey(typeof(Prospect), @"ProgressId").HasForeignKey(typeof(InteractionProcess), @"Id").IsRequired(true);

            modelBuilder.Entity<InteractionDate>().HasOne(x => x.User).WithMany(op => op.InteractionDates).HasForeignKey(@"UserId").IsRequired(true);
        }

        partial void CustomizeMapping(ref ModelBuilder modelBuilder);

        public bool HasChanges()
        {
            return ChangeTracker.Entries().Any(e => e.State == Microsoft.EntityFrameworkCore.EntityState.Added || e.State == Microsoft.EntityFrameworkCore.EntityState.Modified || e.State == Microsoft.EntityFrameworkCore.EntityState.Deleted);
        }

        partial void OnCreated();
    }
}
