using MeteoWebApp.Models;
using Microsoft.EntityFrameworkCore;

namespace MeteoWebApp.Data
{
    public class MeteoDbContext : DbContext
    {
        public MeteoDbContext(DbContextOptions<MeteoDbContext> options) : base(options)
        {

        }
        public DbSet<Station> Stations { get; set; }
        public DbSet<Measurement> Measurements { get; set; }
        public DbSet<Login> Logins { get; set; }

        /* Create relation for table Stations and Measurements */
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            // 1:N relation >> Stations.StationId:Measurements.StationId
            modelBuilder.Entity<Measurement>().HasOne<Station>(M => M.Station).WithMany(S => S.Measurements).HasForeignKey(M => M.StationId);
        }
    }
}
