using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;
using PositioningWebApp.Models.Login;
using PositioningWebApp.Security;

namespace PositioningWebApp.Models.DB
{
    public partial class DevicesOnMapBackgroundContext : DbContext
    {
		public DevicesOnMapBackgroundContext()
		{
		}

		public DevicesOnMapBackgroundContext(DbContextOptions<DevicesOnMapBackgroundContext> options)
			: base(options)
		{
		}

		public virtual DbSet<Devices> Devices { get; set; }
		public virtual DbSet<DeviceZone> DeviceZone { get; set; }
		public virtual DbSet<GroupDevice> GroupDevice { get; set; }
		public virtual DbSet<Groups> Groups { get; set; }
		public virtual DbSet<GroupUsers> GroupUsers { get; set; }
		public virtual DbSet<LogBook> LogBook { get; set; }
		public virtual DbSet<Points> Points { get; set; }
		public virtual DbSet<Users> Users { get; set; }
		public virtual DbSet<Zones> Zones { get; set; }

		protected override void OnModelCreating(ModelBuilder modelBuilder)
        {

			modelBuilder.Entity<Devices>(entity =>
			{
				entity.Property(e => e.Id).HasColumnName("ID");

				entity.Property(e => e.Identifier)
					.IsRequired()
					.HasMaxLength(50)
					.IsUnicode(false);

				entity.Property(e => e.OwnerId).HasColumnName("OwnerID");

				entity.Property(e => e.Title)
					.IsRequired()
					.HasMaxLength(50)
					.IsUnicode(false);

				entity.Property(e => e.ZoneSmsalert).HasColumnName("ZoneSMSAlert");

				entity.HasOne(d => d.Owner)
					.WithMany(p => p.Devices)
					.HasForeignKey(d => d.OwnerId)
					.HasConstraintName("FK__Devices__OwnerID__4E88ABD4");
			});

			modelBuilder.Entity<DeviceZone>(entity =>
			{
				entity.Property(e => e.Id).HasColumnName("ID");

				entity.HasOne(d => d.IdDeviceNavigation)
					.WithMany(p => p.DeviceZone)
					.HasForeignKey(d => d.IdDevice)
					.HasConstraintName("FK__DeviceZon__IdDev__5165187F");

				entity.HasOne(d => d.IdZoneNavigation)
					.WithMany(p => p.DeviceZone)
					.HasForeignKey(d => d.IdZone)
					.HasConstraintName("FK__DeviceZon__IdZon__52593CB8");

			});

			modelBuilder.Entity<GroupDevice>(entity =>
			{
				entity.Property(e => e.Id).HasColumnName("ID");

				entity.Property(e => e.Iddevice).HasColumnName("IDDevice");

				entity.Property(e => e.Idgroup).HasColumnName("IDGroup");

				entity.HasOne(d => d.IddeviceNavigation)
					.WithMany(p => p.GroupDevice)
					.HasForeignKey(d => d.Iddevice)
					.HasConstraintName("FK__GroupDevi__IDDev__5CD6CB2B");

				entity.HasOne(d => d.IdgroupNavigation)
					.WithMany(p => p.GroupDevice)
					.HasForeignKey(d => d.Idgroup)
					.HasConstraintName("FK__GroupDevi__IDGro__5BE2A6F2");
			});

			modelBuilder.Entity<Groups>(entity =>
			{
				entity.Property(e => e.Id).HasColumnName("ID");

				entity.Property(e => e.NameGroup)
					.IsRequired()
					.HasMaxLength(50)
					.IsUnicode(false);

				entity.Property(e => e.OwnerId).HasColumnName("OwnerID");

				entity.HasOne(d => d.Owner)
					.WithMany(p => p.Groups)
					.HasForeignKey(d => d.OwnerId)
					.HasConstraintName("FK__Groups__OwnerID__59063A47");
			});

			modelBuilder.Entity<GroupUsers>(entity =>
			{
				entity.Property(e => e.Id).HasColumnName("ID");

				entity.Property(e => e.Idgroup).HasColumnName("IDGroup");

				entity.Property(e => e.UserId).HasColumnName("UserID");

				entity.HasOne(d => d.IdgroupNavigation)
					.WithMany(p => p.GroupUsers)
					.HasForeignKey(d => d.Idgroup)
					.HasConstraintName("FK__GroupUser__IDGro__5FB337D6");

				entity.HasOne(d => d.User)
					.WithMany(p => p.GroupUsers)
					.HasForeignKey(d => d.UserId)
					.HasConstraintName("FK__GroupUser__UserI__60A75C0F");
			});

			modelBuilder.Entity<LogBook>(entity =>
			{
				entity.Property(e => e.Id).HasColumnName("ID");

				entity.Property(e => e.Arrival).HasColumnType("datetime");

				entity.Property(e => e.Departure).HasColumnType("datetime");

				entity.Property(e => e.Purpose)
					.HasMaxLength(100)
					.IsUnicode(false);

				entity.HasOne(d => d.IdDeviceNavigation)
					.WithMany(p => p.LogBook)
					.HasForeignKey(d => d.IdDevice)
					.HasConstraintName("FK__LogBook__IdDevic__6383C8BA");
			});

			modelBuilder.Entity<Points>(entity =>
			{
				entity.Property(e => e.Id).HasColumnName("ID");

				entity.Property(e => e.CreatedDateTime).HasColumnType("datetime");

				entity.Property(e => e.DeviceId).HasColumnName("DeviceID");

				entity.Property(e => e.ZoneId).HasColumnName("ZoneID");

				entity.HasOne(d => d.Device)
					.WithMany(p => p.Points)
					.HasForeignKey(d => d.DeviceId)
					.HasConstraintName("FK__Points__DeviceID__5535A963");

				entity.HasOne(d => d.Zone)
					.WithMany(p => p.Points)
					.HasForeignKey(d => d.ZoneId)
					.HasConstraintName("FK__Points__ZoneID__5629CD9C");
			});

			modelBuilder.Entity<Users>(entity =>
			{
				entity.Property(e => e.Id).HasColumnName("ID");

				entity.Property(e => e.CreationDate).HasColumnType("datetime");

				entity.Property(e => e.Email)
					.IsRequired()
					.HasMaxLength(50)
					.IsUnicode(false);

				entity.Property(e => e.FirstName)
					.IsRequired()
					.HasMaxLength(50)
					.IsUnicode(false);

				entity.Property(e => e.PasswordHash)
					.IsRequired()
					.HasMaxLength(50)
					.IsUnicode(false);

				entity.Property(e => e.PhoneNumber)
					.IsRequired()
					.HasMaxLength(50)
					.IsUnicode(false);

				entity.Property(e => e.Surname)
					.IsRequired()
					.HasMaxLength(50)
					.IsUnicode(false);
			});

			modelBuilder.Entity<Zones>(entity =>
			{
				entity.Property(e => e.Id).HasColumnName("ID");

				entity.Property(e => e.OwnerId).HasColumnName("OwnerID");

				entity.Property(e => e.Title)
					.HasMaxLength(50)
					.IsUnicode(false);

				entity.HasOne(d => d.Owner)
					.WithMany(p => p.Zones)
					.HasForeignKey(d => d.OwnerId)
					.HasConstraintName("FK__Zones__OwnerID__4BAC3F29");
			});
		}
	}
}
