// <auto-generated> This file has been auto generated by EF Core Power Tools. </auto-generated>
#nullable disable
using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore;
using Pos.Api.Database.Models;

namespace Pos.Api.Database.Data;

public partial class PosApiContext : DbContext
{
    public PosApiContext(DbContextOptions<PosApiContext> options)
        : base(options)
    {
    }

    public virtual DbSet<Employee> Employees { get; set; }

    public virtual DbSet<LastUpdate> LastUpdates { get; set; }

    public virtual DbSet<Payment> Payments { get; set; }

    public virtual DbSet<Product> Products { get; set; }

    public virtual DbSet<Productgroup> Productgroups { get; set; }

    public virtual DbSet<Sale> Sales { get; set; }

    public virtual DbSet<SaleLine> SaleLines { get; set; }

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder
            .UseCollation("latin1_swedish_ci")
            .HasCharSet("latin1");

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

            entity
                .ToTable("employee")
                .HasCharSet("utf8mb4")
                .UseCollation("utf8mb4_general_ci");

            entity.Property(e => e.Id).HasColumnType("int(11)");
            entity.Property(e => e.IsArchived).HasColumnType("tinyint(4)");
            entity.Property(e => e.Name)
                .IsRequired()
                .HasMaxLength(50);
        });

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

            entity.Property(e => e.DateTime).HasColumnType("datetime");
        });

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

            entity
                .ToTable("payment")
                .HasCharSet("armscii8")
                .UseCollation("armscii8_bin");

            entity.Property(e => e.Id).HasColumnType("int(11)");
            entity.Property(e => e.Amount).HasPrecision(20, 6);
            entity.Property(e => e.SaleId).HasColumnType("int(11)");
            entity.Property(e => e.Type)
                .IsRequired()
                .HasColumnType("tinytext");
        });

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

            entity
                .ToTable("product")
                .HasCharSet("utf8mb4")
                .UseCollation("utf8mb4_general_ci");

            entity.HasIndex(e => e.ProductGroupId, "FK_Product_Categories");

            entity.Property(e => e.Id)
                .ValueGeneratedOnAdd()
                .HasColumnType("int(11)");
            entity.Property(e => e.Description).HasColumnType("mediumtext");
            entity.Property(e => e.Index).HasColumnType("int(11)");
            entity.Property(e => e.IsArchived).HasColumnType("tinyint(4)");
            entity.Property(e => e.Name)
                .IsRequired()
                .HasColumnType("tinytext");
            entity.Property(e => e.Price).HasPrecision(10, 2);
            entity.Property(e => e.ProductGroupId).HasColumnType("int(11)");

            entity.HasOne(d => d.IdNavigation).WithOne(p => p.Product)
                .HasForeignKey<Product>(d => d.Id)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK_Product_ProductGroup");
        });

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

            entity
                .ToTable("productgroup")
                .HasCharSet("utf8mb4")
                .UseCollation("utf8mb4_general_ci");

            entity.Property(e => e.Id).HasColumnType("int(11)");
            entity.Property(e => e.Index).HasColumnType("int(11)");
            entity.Property(e => e.IsArchived).HasColumnType("tinyint(4)");
            entity.Property(e => e.Name)
                .IsRequired()
                .HasColumnType("tinytext");
        });

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

            entity
                .ToTable("sale")
                .HasCharSet("armscii8")
                .UseCollation("armscii8_bin");

            entity.Property(e => e.Id).HasColumnType("int(11)");
            entity.Property(e => e.EmployeeId).HasColumnType("int(11)");
            entity.Property(e => e.Time).HasColumnType("datetime");
        });

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

            entity
                .ToTable("sale_line")
                .HasCharSet("armscii8")
                .UseCollation("armscii8_bin");

            entity.Property(e => e.Id).HasColumnType("int(11)");
            entity.Property(e => e.Pieces).HasColumnType("smallint(6)");
            entity.Property(e => e.Price).HasPrecision(20, 6);
            entity.Property(e => e.Product)
                .IsRequired()
                .HasColumnType("tinytext");
            entity.Property(e => e.SaleId).HasColumnType("int(11)");
            entity.Property(e => e.Total).HasPrecision(20, 6);
        });

        OnModelCreatingPartial(modelBuilder);
    }

    partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
}