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

namespace FamilyTreeAPI.Models
{
    public partial class FamilyTreeDBContext : DbContext
    {
        public FamilyTreeDBContext()
        {
        }

        public FamilyTreeDBContext(DbContextOptions<FamilyTreeDBContext> options)
            : base(options)
        {
            AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
        }

        public virtual DbSet<Person> Persons { get; set; } = null!;
        public virtual DbSet<RelationShip> RelationShips { get; set; } = null!;
        public virtual DbSet<Lookup> Lookups { get; set; } = null!;
        public virtual DbSet<staff> staff { get; set; } = null!;
        public virtual DbSet<PersonPhoto> PersonPhotos { get; set; } = null!;


        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Person>(entity =>
            {
                entity.ToTable("person");

                entity.Property(e => e.Id).HasColumnName("id");

                entity.Property(e => e.Address)
                    .HasMaxLength(120)
                    .HasColumnName("address");

                entity.Property(e => e.Alive).HasColumnName("alive");
                entity.Property(e => e.dob).HasColumnName("dob");
                entity.Property(e => e.MotherId).HasColumnName("motherid");
                entity.Property(e => e.FatherId).HasColumnName("fatherid");

                entity.Property(e => e.FirstName)
                    .HasMaxLength(70)
                    .HasColumnName("firstname");
                entity.Property(e => e.Sex)
                    .HasMaxLength(10)
                    .HasColumnName("sex");
                entity.Property(e => e.Image)
                   .HasMaxLength(300)
                   .HasColumnName("image");

                entity.Property(e => e.LastName)
                    .HasMaxLength(70)
                    .HasColumnName("lastname");

                entity.Property(e => e.Email)
                    .HasMaxLength(80)
                    .HasColumnName("email");

                entity.Property(e => e.Phone)
                    .HasMaxLength(30)
                    .HasColumnName("phone");
            });

            modelBuilder.Entity<RelationShip>(entity =>
            {
                entity.ToTable("relationship");

                entity.Property(e => e.Id).HasColumnName("id");
                entity.Property(e => e.RelatePersonId).HasColumnName("relatepersonid");
                entity.Property(e => e.PersonId).HasColumnName("personid");

            });

            modelBuilder.Entity<PersonPhoto>(entity =>
            {
                entity.ToTable("personphoto");

                entity.Property(e => e.Id).HasColumnName("id");
                entity.Property(e => e.PersonId).HasColumnName("personid");
                entity.Property(e => e.Photo)                 
                .HasColumnName("photo");
                entity.Property(e => e.PhotoType)
                .HasMaxLength(20)
                .HasColumnName("phototype");
                entity.Property(e => e.ImagePhoto).HasColumnName("imagephot"); //try to store binary in table. "bytea"

            });


            modelBuilder.Entity<Lookup>(entity =>
            {
                entity.ToTable("lookup");

                entity.Property(e => e.Id).HasColumnName("id");

                entity.Property(e => e.Code)
                    .HasMaxLength(10)
                    .HasColumnName("code");

                entity.Property(e => e.Description)
                    .HasMaxLength(80)
                    .HasColumnName("description");

                entity.Property(e => e.Lactive).HasColumnName("lactive");

                entity.Property(e => e.Type).HasMaxLength(20)
                .HasColumnName("ltype");
            });

            modelBuilder.Entity<staff>(entity =>
            {
                entity.ToTable("staff");
                entity.Property(e => e.Id).HasColumnName("id");

                entity.Property(e => e.Email)
                    .HasMaxLength(80)
                    .HasColumnName("email");

                entity.Property(e => e.Firstname)
                    .HasMaxLength(70)
                    .HasColumnName("firstname");

                entity.Property(e => e.Lastname)
                    .HasMaxLength(70)
                    .HasColumnName("lastname");

                entity.Property(e => e.Phone)
                    .HasMaxLength(30)
                    .HasColumnName("phone");

                entity.Property(e => e.Sactive).HasColumnName("sactive");

                entity.Property(e => e.Spassword)
                    .HasMaxLength(200)
                    .HasColumnName("spassword");

                entity.Property(e => e.Srole).HasColumnName("srole");

                entity.Property(e => e.Stype).HasColumnName("stype");
            });

           

            OnModelCreatingPartial(modelBuilder);
        }

        partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
    }
}
