using Microsoft.EntityFrameworkCore;
using TravelCompanyDatabaseImplement.Models;
using TravelCompanyDatabaseImplement.Models.TouristModel;
using TravelCompanyDatabaseImplement.Models.OperatorModels;
using VisioForge.Libs.MediaFoundation.OPM;

namespace TravelCompanyDatabaseImplement
{
    public class TravelCompanyDatabase : DbContext
    {
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            if (optionsBuilder.IsConfigured == false)
            {
                optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-0IOO2C0;Initial Catalog= TravelCompanyDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
            }
            base.OnConfiguring(optionsBuilder);
        }
        public virtual DbSet<Excursion> Excursions { set; get; }
        public virtual DbSet<Place> Places { set; get; }
        public virtual DbSet<Travel> Travels { set; get; }
        public virtual DbSet<Tourist> Tourists { set; get; }
        public virtual DbSet<ExcursionTravel> ExcursionTravels { set; get; }
        public virtual DbSet<Tour> Tours { set; get; }
        public virtual DbSet<TourTravel> TourTravels { set; get; }
        public virtual DbSet<Guide> Guides { set; get; }
        public virtual DbSet<GuideExcursion> GuideExcursions { set; get; }
        public virtual DbSet<Operator> Operators { set; get; }
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            
            modelBuilder.Entity<Tourist>()
               .HasMany(p => p.Places)
               .WithOne(e => e.Tourist)
               .OnDelete(DeleteBehavior.NoAction);
            modelBuilder.Entity<Tourist>()
               .HasMany(p => p.Travels)
               .WithOne(e => e.Tourist)
               .OnDelete(DeleteBehavior.NoAction);
            modelBuilder.Entity<Tourist>()
               .HasMany(p => p.Excursions)
               .WithOne(e => e.Tourist)
               .OnDelete(DeleteBehavior.NoAction);
            modelBuilder.Entity<Operator>()
              .HasMany(p => p.Tours)
              .WithOne(e => e.Operator)
              .OnDelete(DeleteBehavior.NoAction);
            modelBuilder.Entity<Operator>()
              .HasMany(p => p.Guides)
              .WithOne(e => e.Operator)
              .OnDelete(DeleteBehavior.NoAction);
            modelBuilder.Entity<Excursion>()
                .HasMany(p => p.Places)
                .WithOne(e => e.Excursion)
                .OnDelete(DeleteBehavior.NoAction);
        }





    }
}
