using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;

namespace nukakto.Models
{
    public partial class gr606_kusanContext : DbContext
    {
        public gr606_kusanContext()
        {
        }

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

        public virtual DbSet<Attraction> Attractions { get; set; } = null!;
        public virtual DbSet<Card> Cards { get; set; } = null!;
        public virtual DbSet<Stock> Stocks { get; set; } = null!;
        public virtual DbSet<TypeAttraction> TypeAttractions { get; set; } = null!;
        public virtual DbSet<User> Users { get; set; } = null!;

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            if (!optionsBuilder.IsConfigured)
            {
                optionsBuilder.UseSqlServer("Data source=mssql;Database=gr606_kusan;Integrated Security=true;");
            }
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Attraction>(entity =>
            {
                entity.HasKey(e => e.IdAttractions);

                entity.Property(e => e.AgeLimit).HasMaxLength(50);

                entity.Property(e => e.Name).HasMaxLength(50);

                entity.Property(e => e.Price).HasColumnType("money");

                entity.HasOne(d => d.IdUserNavigation)
                    .WithMany(p => p.Attractions)
                    .HasForeignKey(d => d.IdUser)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_Attractions_User");
            });

            modelBuilder.Entity<Card>(entity =>
            {
                entity.HasKey(e => e.IdCard);

                entity.ToTable("Card");

                entity.Property(e => e.Balance).HasColumnType("money");

                entity.Property(e => e.Bonus).HasColumnType("money");

                entity.Property(e => e.DataCard).HasColumnType("date");

                entity.Property(e => e.NumberCard).HasMaxLength(50);

                entity.HasOne(d => d.IdUserNavigation)
                    .WithMany(p => p.Cards)
                    .HasForeignKey(d => d.IdUser)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_Card_User");
            });

            modelBuilder.Entity<Stock>(entity =>
            {
                entity.HasKey(e => e.IdStock);

                entity.ToTable("Stock");

                entity.Property(e => e.Comment).HasMaxLength(300);

                entity.Property(e => e.DateEnd).HasColumnType("date");

                entity.Property(e => e.DateStart).HasColumnType("date");

                entity.Property(e => e.Icon).HasColumnType("image");

                entity.HasOne(d => d.IdAttractionsNavigation)
                    .WithMany(p => p.Stocks)
                    .HasForeignKey(d => d.IdAttractions)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_Stock_Attractions");
            });

            modelBuilder.Entity<TypeAttraction>(entity =>
            {
                entity.HasKey(e => e.IdType);

                entity.Property(e => e.Name).HasMaxLength(50);

                entity.HasOne(d => d.IdAttractionsNavigation)
                    .WithMany(p => p.TypeAttractions)
                    .HasForeignKey(d => d.IdAttractions)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_TypeAttractions_Attractions");
            });

            modelBuilder.Entity<User>(entity =>
            {
                entity.HasKey(e => e.IdUser);

                entity.ToTable("User");

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

                entity.Property(e => e.LastName).HasMaxLength(50);

                entity.Property(e => e.Login).HasMaxLength(50);

                entity.Property(e => e.MiddleName).HasMaxLength(50);

                entity.Property(e => e.Password).HasMaxLength(50);
            });

            OnModelCreatingPartial(modelBuilder);
        }

        partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
    }
}
