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

namespace administration.Models;

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

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

    public virtual DbSet<AdditionalSource> AdditionalSources { get; set; }

    public virtual DbSet<Expense> Expenses { get; set; }

    public virtual DbSet<Logo> Logos { get; set; }

    public virtual DbSet<Revenue> Revenues { get; set; }

    public virtual DbSet<User> Users { 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.UseSqlServer("Server=217.154.116.43;Database=Finances;User Id=sa;Password=Mf33ksTRLrPKSqQ4cTXitgiSN6BPBt89;TrustServerCertificate=True;");

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

            entity.Property(e => e.Id).HasColumnName("id");
            entity.Property(e => e.Amount).HasColumnName("amount");
            entity.Property(e => e.Date).HasColumnName("date");
            entity.Property(e => e.Description).HasColumnName("description");
            entity.Property(e => e.LogoId).HasColumnName("logo_id");
            entity.Property(e => e.TransactionType)
                .HasMaxLength(50)
                .HasColumnName("transaction_type");
            entity.Property(e => e.UserId)
                .HasDefaultValue(2)
                .HasColumnName("user_id");

            entity.HasOne(d => d.Logo).WithMany(p => p.AdditionalSources)
                .HasForeignKey(d => d.LogoId)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK_AdditionalSource_Logo");

            entity.HasOne(d => d.User).WithMany(p => p.AdditionalSources)
                .HasForeignKey(d => d.UserId)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK_AdditionalSource_User");
        });

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

            entity.Property(e => e.Id).HasColumnName("id");
            entity.Property(e => e.Date).HasColumnName("date");
            entity.Property(e => e.Electricity).HasColumnName("electricity");
            entity.Property(e => e.Groceries).HasColumnName("groceries");
            entity.Property(e => e.Insurance).HasColumnName("insurance");
            entity.Property(e => e.Rent).HasColumnName("rent");
            entity.Property(e => e.Saving)
                .HasMaxLength(10)
                .IsFixedLength()
                .HasColumnName("saving");
            entity.Property(e => e.Trash).HasColumnName("trash");
            entity.Property(e => e.UserId).HasColumnName("user_id");
            entity.Property(e => e.Wifi).HasColumnName("wifi");

            entity.HasOne(d => d.User).WithMany(p => p.Expenses)
                .HasForeignKey(d => d.UserId)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK_Expense_User");
        });

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

            entity.Property(e => e.Id).HasColumnName("id");
            entity.Property(e => e.Image)
                .HasColumnType("image")
                .HasColumnName("image");
            entity.Property(e => e.Name)
                .HasMaxLength(50)
                .HasColumnName("name");
        });

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

            entity.Property(e => e.Id).HasColumnName("id");
            entity.Property(e => e.Salary).HasColumnName("salary");
            entity.Property(e => e.UserId).HasColumnName("user_id");

            entity.HasOne(d => d.User).WithMany(p => p.Revenues)
                .HasForeignKey(d => d.UserId)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK_Revenue_User");
        });

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

            entity.Property(e => e.Id).HasColumnName("id");
            entity.Property(e => e.Name)
                .HasMaxLength(50)
                .HasColumnName("name");
        });

        OnModelCreatingPartial(modelBuilder);
    }

    partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
}
