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

namespace Register_office.Properties;

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

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

	public virtual DbSet<Disease> Diseases { get; set; }

	public virtual DbSet<DiseaseSyndrome> DiseaseSyndromes { get; set; }

	public virtual DbSet<Doctor> Doctors { get; set; }

	public virtual DbSet<DrugIntakeMethod> DrugIntakeMethods { get; set; }

	public virtual DbSet<DrugType> DrugTypes { get; set; }

	public virtual DbSet<DrugTypePrescription> DrugTypePrescriptions { get; set; }

	public virtual DbSet<ExaminationType> ExaminationTypes { get; set; }

	public virtual DbSet<ExaminationTypePrescription> ExaminationTypePrescriptions { get; set; }

	public virtual DbSet<HospitalAdmission> HospitalAdmissions { get; set; }

	public virtual DbSet<HospitalDischarge> HospitalDischarges { get; set; }

	public virtual DbSet<NumericResult> NumericResults { get; set; }

	public virtual DbSet<Patient> Patients { get; set; }

	public virtual DbSet<Person> People { get; set; }

	public virtual DbSet<Prescription> Prescriptions { get; set; }

	public virtual DbSet<ProcedureType> ProcedureTypes { get; set; }

	public virtual DbSet<ProcedureTypePrescription> ProcedureTypePrescriptions { get; set; }

	public virtual DbSet<QualitativeResult> QualitativeResults { get; set; }

	public virtual DbSet<ReferenceNumericValue> ReferenceNumericValues { get; set; }

	public virtual DbSet<ReferenceQualitativeValue> ReferenceQualitativeValues { get; set; }

	public virtual DbSet<ReferenceValue> ReferenceValues { get; set; }

	public virtual DbSet<Registrar> Registrars { get; set; }

	public virtual DbSet<Result> Results { get; set; }

	public virtual DbSet<SyndromeExaminationType> SyndromeExaminationTypes { get; set; }

	public virtual DbSet<SyndromeType> SyndromeTypes { get; set; }

	public virtual DbSet<Unit> Units { get; set; }

	protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
#warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see https://go.microsoft.com/fwlink/?LinkId=723263.
		=> optionsBuilder.UseNpgsql("Host=localhost;Port=5432;Database=register_office;Username=postgres;Password=slavik242");

	protected override void OnModelCreating(ModelBuilder modelBuilder)
	{
		modelBuilder
			.HasPostgresEnum("examination_categories_enum", new[] { "physical", "laboratory", "instrumental" })
			.HasPostgresEnum("gender_enum", new[] { "male", "female" })
			.HasPostgresEnum("hospital_discharge_reason_enum", new[] { "death", "improvement", "refusal" })
			.HasPostgresEnum("unit_context_enum", new[] { "examination", "medication" });

		modelBuilder.Entity<Disease>(entity =>
		{
			entity.HasKey(e => e.DiseaseId).HasName("disease_pkey");

			entity.ToTable("disease");

			entity.HasIndex(e => e.IcdCode, "disease_icd_code_key").IsUnique();

			entity.HasIndex(e => e.Name, "disease_name_key").IsUnique();

			entity.Property(e => e.DiseaseId).HasColumnName("disease_id");
			entity.Property(e => e.IcdCode).HasColumnName("icd_code");
			entity.Property(e => e.Name).HasColumnName("name");
		});

		modelBuilder.Entity<DiseaseSyndrome>(entity =>
		{
			entity.HasKey(e => e.DiseaseSyndromeId).HasName("disease_syndrome_pkey");

			entity.ToTable("disease_syndrome");

			entity.HasIndex(e => new { e.DiseaseId, e.SyndromeId }, "disease_syndrome_disease_id_syndrome_id_key").IsUnique();

			entity.Property(e => e.DiseaseSyndromeId).HasColumnName("disease_syndrome_id");
			entity.Property(e => e.DiseaseId).HasColumnName("disease_id");
			entity.Property(e => e.SyndromeId).HasColumnName("syndrome_id");

			entity.HasOne(d => d.Disease).WithMany(p => p.DiseaseSyndromes)
				.HasForeignKey(d => d.DiseaseId)
				.HasConstraintName("disease_syndrome_disease_id_fkey");

			entity.HasOne(d => d.Syndrome).WithMany(p => p.DiseaseSyndromes)
				.HasForeignKey(d => d.SyndromeId)
				.HasConstraintName("disease_syndrome_syndrome_id_fkey");
		});

		modelBuilder.Entity<Doctor>(entity =>
		{
			entity.HasKey(e => e.DoctorId).HasName("doctor_pkey");

			entity.ToTable("doctor");

			entity.Property(e => e.DoctorId)
				.ValueGeneratedNever()
				.HasColumnName("doctor_id");

			entity.HasOne(d => d.DoctorNavigation).WithOne(p => p.Doctor)
				.HasForeignKey<Doctor>(d => d.DoctorId)
				.OnDelete(DeleteBehavior.ClientSetNull)
				.HasConstraintName("doctor_doctor_id_fkey");
		});

		modelBuilder.Entity<DrugIntakeMethod>(entity =>
		{
			entity.HasKey(e => e.DrugIntakeMethodId).HasName("drug_intake_method_pkey");

			entity.ToTable("drug_intake_method");

			entity.HasIndex(e => e.Name, "drug_intake_method_name_key").IsUnique();

			entity.Property(e => e.DrugIntakeMethodId).HasColumnName("drug_intake_method_id");
			entity.Property(e => e.Name).HasColumnName("name");
		});

		modelBuilder.Entity<DrugType>(entity =>
		{
			entity.HasKey(e => e.DrugTypeId).HasName("drug_type_pkey");

			entity.ToTable("drug_type");

			entity.HasIndex(e => e.BrandNameRu, "drug_type_brand_name_ru_key").IsUnique();

			entity.HasIndex(e => e.InternationalNameEn, "drug_type_international_name_en_key").IsUnique();

			entity.HasIndex(e => e.InternationalNameLa, "drug_type_international_name_la_key").IsUnique();

			entity.HasIndex(e => e.InternationalNameRu, "drug_type_international_name_ru_key").IsUnique();

			entity.Property(e => e.DrugTypeId).HasColumnName("drug_type_id");
			entity.Property(e => e.BrandNameRu).HasColumnName("brand_name_ru");
			entity.Property(e => e.InternationalNameEn).HasColumnName("international_name_en");
			entity.Property(e => e.InternationalNameLa).HasColumnName("international_name_la");
			entity.Property(e => e.InternationalNameRu).HasColumnName("international_name_ru");
		});

		modelBuilder.Entity<DrugTypePrescription>(entity =>
		{
			entity.HasKey(e => e.DrugPrescriptionId).HasName("drug_type_prescription_pkey");

			entity.ToTable("drug_type_prescription");

			entity.HasIndex(e => e.PrescriptionId, "drug_type_prescription_prescription_id_key").IsUnique();

			entity.Property(e => e.DrugPrescriptionId).HasColumnName("drug_prescription_id");
			entity.Property(e => e.Dose).HasColumnName("dose");
			entity.Property(e => e.DoseUnitId).HasColumnName("dose_unit_id");
			entity.Property(e => e.DrugTypeId).HasColumnName("drug_type_id");
			entity.Property(e => e.DurationDays).HasColumnName("duration_days");
			entity.Property(e => e.IntakeMethodId).HasColumnName("intake_method_id");
			entity.Property(e => e.PrescriptionId).HasColumnName("prescription_id");

			entity.HasOne(d => d.DoseUnit).WithMany(p => p.DrugTypePrescriptions)
				.HasForeignKey(d => d.DoseUnitId)
				.OnDelete(DeleteBehavior.Restrict)
				.HasConstraintName("drug_type_prescription_dose_unit_id_fkey");

			entity.HasOne(d => d.DrugType).WithMany(p => p.DrugTypePrescriptions)
				.HasForeignKey(d => d.DrugTypeId)
				.OnDelete(DeleteBehavior.Restrict)
				.HasConstraintName("drug_type_prescription_drug_type_id_fkey");

			entity.HasOne(d => d.IntakeMethod).WithMany(p => p.DrugTypePrescriptions)
				.HasForeignKey(d => d.IntakeMethodId)
				.OnDelete(DeleteBehavior.Restrict)
				.HasConstraintName("drug_type_prescription_intake_method_id_fkey");

			entity.HasOne(d => d.Prescription).WithOne(p => p.DrugTypePrescription)
				.HasForeignKey<DrugTypePrescription>(d => d.PrescriptionId)
				.HasConstraintName("drug_type_prescription_prescription_id_fkey");
		});

		modelBuilder.Entity<ExaminationType>(entity =>
		{
			entity.HasKey(e => e.ExaminationTypeId).HasName("examination_type_pkey");

			entity.ToTable("examination_type");

			entity.HasIndex(e => e.Name, "examination_type_name_key").IsUnique();

			entity.Property(e => e.ExaminationTypeId).HasColumnName("examination_type_id");
			entity.Property(e => e.Name).HasColumnName("name");
			entity.Property(e => e.Category).HasColumnName("category");
		});

		modelBuilder.Entity<ExaminationTypePrescription>(entity =>
		{
			entity.HasKey(e => e.ExaminationPrescriptionId).HasName("examination_type_prescription_pkey");

			entity.ToTable("examination_type_prescription");

			entity.HasIndex(e => e.PrescriptionId, "examination_type_prescription_prescription_id_key").IsUnique();

			entity.Property(e => e.ExaminationPrescriptionId).HasColumnName("examination_prescription_id");
			entity.Property(e => e.ExaminationTypeId).HasColumnName("examination_type_id");
			entity.Property(e => e.PrescriptionId).HasColumnName("prescription_id");
			entity.Property(e => e.ResultId).HasColumnName("result_id");

			entity.HasOne(d => d.ExaminationType).WithMany(p => p.ExaminationTypePrescriptions)
				.HasForeignKey(d => d.ExaminationTypeId)
				.HasConstraintName("examination_type_prescription_examination_type_id_fkey");

			entity.HasOne(d => d.Prescription).WithOne(p => p.ExaminationTypePrescription)
				.HasForeignKey<ExaminationTypePrescription>(d => d.PrescriptionId)
				.HasConstraintName("examination_type_prescription_prescription_id_fkey");

			entity.HasOne(d => d.Result).WithMany(p => p.ExaminationTypePrescriptions)
				.HasForeignKey(d => d.ResultId)
				.HasConstraintName("examination_type_prescription_result_id_fkey");
		});

		modelBuilder.Entity<HospitalAdmission>(entity =>
		{
			entity.HasKey(e => e.HospitalAdmissionId).HasName("hospital_admission_pkey");

			entity.ToTable("hospital_admission");

			entity.Property(e => e.HospitalAdmissionId).HasColumnName("hospital_admission_id");
			entity.Property(e => e.AdmissionDatetime)
				.HasColumnType("timestamp without time zone")
				.HasColumnName("admission_datetime");
			entity.Property(e => e.PatientId).HasColumnName("patient_id");
			entity.Property(e => e.PreliminaryDiseaseId).HasColumnName("preliminary_disease_id");

			entity.HasOne(d => d.Patient).WithMany(p => p.HospitalAdmissions)
				.HasForeignKey(d => d.PatientId)
				.HasConstraintName("hospital_admission_patient_id_fkey");

			entity.HasOne(d => d.PreliminaryDisease).WithMany(p => p.HospitalAdmissions)
				.HasForeignKey(d => d.PreliminaryDiseaseId)
				.OnDelete(DeleteBehavior.ClientSetNull)
				.HasConstraintName("hospital_admission_preliminary_disease_id_fkey");
		});

		modelBuilder.Entity<HospitalDischarge>(entity =>
		{
			entity.HasKey(e => e.HospitalDischargeId).HasName("hospital_discharge_pkey");

			entity.ToTable("hospital_discharge");

			entity.Property(e => e.HospitalDischargeId).HasColumnName("hospital_discharge_id");
			entity.Property(e => e.DischargeDatetime)
				.HasColumnType("timestamp without time zone")
				.HasColumnName("discharge_datetime");
			entity.Property(e => e.FinalDiseaseId).HasColumnName("final_disease_id");
			entity.Property(e => e.HospitalAdmissionId).HasColumnName("hospital_admission_id");
			entity.Property(e => e.Reason).HasColumnName("reason");

			entity.HasOne(d => d.FinalDisease).WithMany(p => p.HospitalDischarges)
				.HasForeignKey(d => d.FinalDiseaseId)
				.OnDelete(DeleteBehavior.ClientSetNull)
				.HasConstraintName("hospital_discharge_final_disease_id_fkey");

			entity.HasOne(d => d.HospitalAdmission).WithMany(p => p.HospitalDischarges)
				.HasForeignKey(d => d.HospitalAdmissionId)
				.HasConstraintName("hospital_discharge_hospital_admission_id_fkey");
		});

		modelBuilder.Entity<NumericResult>(entity =>
		{
			entity.HasKey(e => e.ResultId).HasName("numeric_result_pkey");

			entity.ToTable("numeric_result");

			entity.Property(e => e.ResultId)
				.ValueGeneratedNever()
				.HasColumnName("result_id");
			entity.Property(e => e.UnitId).HasColumnName("unit_id");
			entity.Property(e => e.Value).HasColumnName("value");

			entity.HasOne(d => d.Result).WithOne(p => p.NumericResult)
				.HasForeignKey<NumericResult>(d => d.ResultId)
				.OnDelete(DeleteBehavior.ClientSetNull)
				.HasConstraintName("numeric_result_result_id_fkey");

			entity.HasOne(d => d.Unit).WithMany(p => p.NumericResults)
				.HasForeignKey(d => d.UnitId)
				.OnDelete(DeleteBehavior.Restrict)
				.HasConstraintName("numeric_result_unit_id_fkey");
		});

		modelBuilder.Entity<Patient>(entity =>
		{
			entity.HasKey(e => e.PatientId).HasName("patient_pkey");

			entity.ToTable("patient");

			entity.Property(e => e.PatientId)
				.ValueGeneratedNever()
				.HasColumnName("patient_id");
			entity.Property(e => e.PolicyNumber).HasColumnName("policy_number");

			entity.HasOne(d => d.PatientNavigation).WithOne(p => p.Patient)
				.HasForeignKey<Patient>(d => d.PatientId)
				.OnDelete(DeleteBehavior.ClientSetNull)
				.HasConstraintName("patient_patient_id_fkey");
		});

		modelBuilder.Entity<Person>(entity =>
		{
			entity.HasKey(e => e.PersonId).HasName("person_pkey");

			entity.ToTable("person");

			entity.Property(e => e.PersonId).HasColumnName("person_id");
			entity.Property(e => e.Address).HasColumnName("address");
			entity.Property(e => e.BirthDate).HasColumnName("birth_date");
			entity.Property(e => e.FirstName).HasColumnName("first_name");
			entity.Property(e => e.LastName).HasColumnName("last_name");
			entity.Property(e => e.MiddleName).HasColumnName("middle_name");
			entity.Property(e => e.Gender).HasColumnName(name: "gender");
		});

		modelBuilder.Entity<Prescription>(entity =>
		{
			entity.HasKey(e => e.PrescriptionId).HasName("prescription_pkey");

			entity.ToTable("prescription");

			entity.Property(e => e.PrescriptionId).HasColumnName("prescription_id");
			entity.Property(e => e.DoctorId).HasColumnName("doctor_id");
			entity.Property(e => e.PatientId).HasColumnName("patient_id");

			entity.HasOne(d => d.Doctor).WithMany(p => p.Prescriptions)
				.HasForeignKey(d => d.DoctorId)
				.OnDelete(DeleteBehavior.Restrict)
				.HasConstraintName("prescription_doctor_id_fkey");

			entity.HasOne(d => d.Patient).WithMany(p => p.Prescriptions)
				.HasForeignKey(d => d.PatientId)
				.HasConstraintName("prescription_patient_id_fkey");
		});

		modelBuilder.Entity<ProcedureType>(entity =>
		{
			entity.HasKey(e => e.ProcedureTypeId).HasName("procedure_type_pkey");

			entity.ToTable("procedure_type");

			entity.HasIndex(e => e.Name, "procedure_type_name_key").IsUnique();

			entity.Property(e => e.ProcedureTypeId).HasColumnName("procedure_type_id");
			entity.Property(e => e.Name).HasColumnName("name");
		});

		modelBuilder.Entity<ProcedureTypePrescription>(entity =>
		{
			entity.HasKey(e => e.ProcedurePrescriptionId).HasName("procedure_type_prescription_pkey");

			entity.ToTable("procedure_type_prescription");

			entity.HasIndex(e => e.PrescriptionId, "procedure_type_prescription_prescription_id_key").IsUnique();

			entity.Property(e => e.ProcedurePrescriptionId).HasColumnName("procedure_prescription_id");
			entity.Property(e => e.PrescriptionId).HasColumnName("prescription_id");
			entity.Property(e => e.ProcedureTypeId).HasColumnName("procedure_type_id");
			entity.Property(e => e.ScheduledDatetime)
				.HasColumnType("timestamp without time zone")
				.HasColumnName("scheduled_datetime");

			entity.HasOne(d => d.Prescription).WithOne(p => p.ProcedureTypePrescription)
				.HasForeignKey<ProcedureTypePrescription>(d => d.PrescriptionId)
				.HasConstraintName("procedure_type_prescription_prescription_id_fkey");

			entity.HasOne(d => d.ProcedureType).WithMany(p => p.ProcedureTypePrescriptions)
				.HasForeignKey(d => d.ProcedureTypeId)
				.OnDelete(DeleteBehavior.Restrict)
				.HasConstraintName("procedure_type_prescription_procedure_type_id_fkey");
		});

		modelBuilder.Entity<QualitativeResult>(entity =>
		{
			entity.HasKey(e => e.ResultId).HasName("qualitative_result_pkey");

			entity.ToTable("qualitative_result");

			entity.Property(e => e.ResultId)
				.ValueGeneratedNever()
				.HasColumnName("result_id");
			entity.Property(e => e.Value).HasColumnName("value");

			entity.HasOne(d => d.Result).WithOne(p => p.QualitativeResult)
				.HasForeignKey<QualitativeResult>(d => d.ResultId)
				.OnDelete(DeleteBehavior.ClientSetNull)
				.HasConstraintName("qualitative_result_result_id_fkey");
		});

		modelBuilder.Entity<ReferenceNumericValue>(entity =>
		{
			entity.HasKey(e => e.ReferenceValueId).HasName("reference_numeric_value_pkey");

			entity.ToTable("reference_numeric_value");

			entity.Property(e => e.ReferenceValueId)
				.ValueGeneratedNever()
				.HasColumnName("reference_value_id");
			entity.Property(e => e.MaxValue).HasColumnName("max_value");
			entity.Property(e => e.MinValue).HasColumnName("min_value");
			entity.Property(e => e.UnitId).HasColumnName("unit_id");

			entity.HasOne(d => d.ReferenceValue).WithOne(p => p.ReferenceNumericValue)
				.HasForeignKey<ReferenceNumericValue>(d => d.ReferenceValueId)
				.HasConstraintName("reference_numeric_value_reference_value_id_fkey");

			entity.HasOne(d => d.Unit).WithMany(p => p.ReferenceNumericValues)
				.HasForeignKey(d => d.UnitId)
				.OnDelete(DeleteBehavior.Restrict)
				.HasConstraintName("reference_numeric_value_unit_id_fkey");
		});

		modelBuilder.Entity<ReferenceQualitativeValue>(entity =>
		{
			entity.HasKey(e => e.ReferenceValueId).HasName("reference_qualitative_value_pkey");

			entity.ToTable("reference_qualitative_value");

			entity.HasIndex(e => new { e.DescriptionTrue, e.DescriptionFalse }, "reference_qualitative_value_description_true_description_fa_key").IsUnique();

			entity.Property(e => e.ReferenceValueId)
				.ValueGeneratedNever()
				.HasColumnName("reference_value_id");
			entity.Property(e => e.DescriptionFalse).HasColumnName("description_false");
			entity.Property(e => e.DescriptionTrue).HasColumnName("description_true");

			entity.HasOne(d => d.ReferenceValue).WithOne(p => p.ReferenceQualitativeValue)
				.HasForeignKey<ReferenceQualitativeValue>(d => d.ReferenceValueId)
				.HasConstraintName("reference_qualitative_value_reference_value_id_fkey");
		});

		modelBuilder.Entity<ReferenceValue>(entity =>
		{
			entity.HasKey(e => e.ReferenceValueId).HasName("reference_value_pkey");

			entity.ToTable("reference_value");

			entity.Property(e => e.ReferenceValueId).HasColumnName("reference_value_id");
			entity.Property(e => e.AgeMax).HasColumnName("age_max");
			entity.Property(e => e.AgeMin).HasColumnName("age_min");
			entity.Property(e => e.ExaminationTypeId).HasColumnName("examination_type_id");
			entity.Property(e => e.Gender).HasColumnName("gender");

			entity.HasOne(d => d.ExaminationType).WithMany(p => p.ReferenceValues)
				.HasForeignKey(d => d.ExaminationTypeId)
				.HasConstraintName("reference_value_examination_type_id_fkey");
		});

		modelBuilder.Entity<Registrar>(entity =>
		{
			entity.HasKey(e => e.RegistrarId).HasName("registrar_pkey");

			entity.ToTable("registrar");

			entity.Property(e => e.RegistrarId)
				.ValueGeneratedNever()
				.HasColumnName("registrar_id");

			entity.HasOne(d => d.RegistrarNavigation).WithOne(p => p.Registrar)
				.HasForeignKey<Registrar>(d => d.RegistrarId)
				.OnDelete(DeleteBehavior.ClientSetNull)
				.HasConstraintName("registrar_registrar_id_fkey");
		});

		modelBuilder.Entity<Result>(entity =>
		{
			entity.HasKey(e => e.ResultId).HasName("result_pkey");

			entity.ToTable("result");

			entity.Property(e => e.ResultId).HasColumnName("result_id");
			entity.Property(e => e.ExaminationId).HasColumnName("examination_id");

			entity.HasOne(d => d.Examination).WithOne(p => p.Result)
				.HasForeignKey<Result>(d => d.ExaminationId)
				.HasConstraintName("result_examination_id_fkey");
		});

		modelBuilder.Entity<SyndromeExaminationType>(entity =>
		{
			entity.HasKey(e => e.SyndromeId).HasName("syndrome_examination_type_pkey");

			entity.ToTable("syndrome_examination_type");

			entity.HasIndex(e => e.ExaminationTypeId, "syndrome_examination_type_examination_type_id_key").IsUnique();

			entity.Property(e => e.SyndromeId)
				.ValueGeneratedNever()
				.HasColumnName("syndrome_id");
			entity.Property(e => e.ExaminationTypeId).HasColumnName("examination_type_id");

			entity.HasOne(d => d.ExaminationType).WithOne(p => p.SyndromeExaminationType)
				.HasForeignKey<SyndromeExaminationType>(d => d.ExaminationTypeId)
				.HasConstraintName("syndrome_examination_type_examination_type_id_fkey");

			entity.HasOne(d => d.Syndrome).WithOne(p => p.SyndromeExaminationType)
				.HasForeignKey<SyndromeExaminationType>(d => d.SyndromeId)
				.HasConstraintName("syndrome_examination_type_syndrome_id_fkey");
		});

		modelBuilder.Entity<SyndromeType>(entity =>
		{
			entity.HasKey(e => e.SyndromeTypeId).HasName("syndrome_type_pkey");

			entity.ToTable("syndrome_type");

			entity.HasIndex(e => e.Name, "syndrome_type_name_key").IsUnique();

			entity.Property(e => e.SyndromeTypeId).HasColumnName("syndrome_type_id");
			entity.Property(e => e.Name).HasColumnName("name");
		});

		modelBuilder.Entity<Unit>(entity =>
		{
			entity.HasKey(e => e.UnitId).HasName("unit_pkey");

			entity.ToTable("unit");

			entity.HasIndex(e => e.Name, "unit_name_key").IsUnique();

			entity.Property(e => e.UnitId).HasColumnName("unit_id");
			entity.Property(e => e.Name).HasColumnName("name");
		});

		OnModelCreatingPartial(modelBuilder);
	}

	partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
}
