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

namespace TravelAroundRussia.Models;

public partial class UpKotkovaContext : DbContext
{
    public UpKotkovaContext()
    {
    }

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

    public virtual DbSet<Country> Countries { get; set; }

    public virtual DbSet<Hotel> Hotels { get; set; }

    public virtual DbSet<HotelComment> HotelComments { get; set; }

    public virtual DbSet<HotelImage> HotelImages { get; set; }

    public virtual DbSet<HotelOfTour> HotelOfTours { get; set; }

    public virtual DbSet<Tour> Tours { get; set; }

    public virtual DbSet<Type> Types { get; set; }

    public virtual DbSet<TypeOfTour> TypeOfTours { get; set; }

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        => optionsBuilder.UseNpgsql("Host=edu.pg.ngknn.local;Port=5432;Database=UP_Kotkova;Username=43P;Password=444444");

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<Country>(entity =>
        {
            entity.HasKey(e => e.Code).HasName("Country_pkey");

            entity.ToTable("country");

            entity.Property(e => e.Code)
                .HasMaxLength(2)
                .IsFixedLength()
                .HasColumnName("code");
            entity.Property(e => e.Name)
                .HasMaxLength(100)
                .HasColumnName("name");
        });

        modelBuilder.Entity<Hotel>(entity =>
        {
            entity.HasKey(e => e.Id).HasName("Hotel_pkey");

            entity.ToTable("hotel");

            entity.Property(e => e.Id)
                .UseIdentityAlwaysColumn()
                .HasColumnName("id");
            entity.Property(e => e.CountOfStars).HasColumnName("count_of_stars");
            entity.Property(e => e.CountryCode)
                .HasMaxLength(2)
                .IsFixedLength()
                .HasColumnName("country_code");
            entity.Property(e => e.Description)
                .HasColumnType("character varying")
                .HasColumnName("description");
            entity.Property(e => e.Name)
                .HasMaxLength(100)
                .HasColumnName("name");

            entity.HasOne(d => d.CountryCodeNavigation).WithMany(p => p.Hotels)
                .HasForeignKey(d => d.CountryCode)
                .HasConstraintName("Hotel_CountryCode_fkey");
        });

        modelBuilder.Entity<HotelComment>(entity =>
        {
            entity.HasKey(e => e.Id).HasName("HotelComment_pkey");

            entity.ToTable("hotel_comment");

            entity.Property(e => e.Id)
                .UseIdentityAlwaysColumn()
                .HasColumnName("id");
            entity.Property(e => e.Author)
                .HasColumnType("character varying")
                .HasColumnName("author");
            entity.Property(e => e.CreationDate).HasColumnName("creation_date");
            entity.Property(e => e.HotelId).HasColumnName("hotel_id");
            entity.Property(e => e.Text)
                .HasMaxLength(100)
                .HasColumnName("text");

            entity.HasOne(d => d.Hotel).WithMany(p => p.HotelComments)
                .HasForeignKey(d => d.HotelId)
                .HasConstraintName("HotelComment_HotelId_fkey");
        });

        modelBuilder.Entity<HotelImage>(entity =>
        {
            entity.HasKey(e => e.Id).HasName("HotelImage_pkey");

            entity.ToTable("hotel_image");

            entity.Property(e => e.Id)
                .UseIdentityAlwaysColumn()
                .HasColumnName("id");
            entity.Property(e => e.HotelId).HasColumnName("hotel_id");
            entity.Property(e => e.ImageSource).HasColumnName("image_source");

            entity.HasOne(d => d.Hotel).WithMany(p => p.HotelImages)
                .HasForeignKey(d => d.HotelId)
                .HasConstraintName("HotelImage_HotelId_fkey");
        });

        modelBuilder.Entity<HotelOfTour>(entity =>
        {
            entity.HasKey(e => e.Id).HasName("HotelOfTour_pkey");

            entity.ToTable("hotel_of_tour");

            entity.Property(e => e.Id)
                .UseIdentityAlwaysColumn()
                .HasColumnName("id");
            entity.Property(e => e.HotelId).HasColumnName("hotel_id");
            entity.Property(e => e.TourId).HasColumnName("tour_id");

            entity.HasOne(d => d.Hotel).WithMany(p => p.HotelOfTours)
                .HasForeignKey(d => d.HotelId)
                .HasConstraintName("HotelOfTour_HotelId_fkey");

            entity.HasOne(d => d.Tour).WithMany(p => p.HotelOfTours)
                .HasForeignKey(d => d.TourId)
                .HasConstraintName("HotelOfTour_TourId_fkey");
        });

        modelBuilder.Entity<Tour>(entity =>
        {
            entity.HasKey(e => e.Id).HasName("Tour_pkey");

            entity.ToTable("tour");

            entity.HasIndex(e => e.CountryCode, "fki_Tour_CountryCode_fley");

            entity.Property(e => e.Id)
                .UseIdentityAlwaysColumn()
                .HasColumnName("id");
            entity.Property(e => e.CountryCode)
                .HasMaxLength(2)
                .IsFixedLength()
                .HasColumnName("country_code");
            entity.Property(e => e.Description)
                .HasColumnType("character varying")
                .HasColumnName("description");
            entity.Property(e => e.ImagePreview)
                .HasColumnType("character varying")
                .HasColumnName("image_preview");
            entity.Property(e => e.IsActual).HasColumnName("is_actual");
            entity.Property(e => e.Name)
                .HasMaxLength(100)
                .HasColumnName("name");
            entity.Property(e => e.Price)
                .HasColumnType("money")
                .HasColumnName("price");
            entity.Property(e => e.TicketCount).HasColumnName("ticket_count");

            entity.HasOne(d => d.CountryCodeNavigation).WithMany(p => p.Tours)
                .HasForeignKey(d => d.CountryCode)
                .HasConstraintName("Tour_CountryCode_fley");
        });

        modelBuilder.Entity<Type>(entity =>
        {
            entity.HasKey(e => e.Id).HasName("Type_pkey");

            entity.ToTable("type");

            entity.Property(e => e.Id)
                .UseIdentityAlwaysColumn()
                .HasColumnName("id");
            entity.Property(e => e.Description)
                .HasColumnType("character varying")
                .HasColumnName("description");
            entity.Property(e => e.Name)
                .HasMaxLength(100)
                .HasColumnName("name");
        });

        modelBuilder.Entity<TypeOfTour>(entity =>
        {
            entity.HasKey(e => e.Id).HasName("TypeOfTour_pkey");

            entity.ToTable("type_of_tour");

            entity.Property(e => e.Id)
                .UseIdentityAlwaysColumn()
                .HasColumnName("id");
            entity.Property(e => e.TourId).HasColumnName("tour_id");
            entity.Property(e => e.TypeId).HasColumnName("type_id");

            entity.HasOne(d => d.Tour).WithMany(p => p.TypeOfTours)
                .HasForeignKey(d => d.TourId)
                .HasConstraintName("TypeOfTour_TourId_fkey");

            entity.HasOne(d => d.Type).WithMany(p => p.TypeOfTours)
                .HasForeignKey(d => d.TypeId)
                .HasConstraintName("TypeOfTour_TypeId_fkey");
        });

        OnModelCreatingPartial(modelBuilder);
    }

    partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
}
