using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using ZpcBulletinBoard.Models;
using ZpcBulletinBoard.Models.Editor;

namespace ZpcBulletinBoard.Data
{
    public class ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
        : IdentityDbContext<IdentityApplicationUser, IdentityApplicationRole, int>(options)
    {
        public DbSet<Note> Notes { get; set; }
        public DbSet<BulletinBoard> BulletinBoards { get; set; }
        public DbSet<BulletinBoardPage> BulletinBoardPage { get; set; }
        public DbSet<BulletinBoardPageLink> BulletinBoardPageLinks { get; set; }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);

            //Relacije
            modelBuilder.Entity<BulletinBoard>()
                .HasMany(t => t.Links)
                .WithOne(t => t.BulletinBoard)
                .OnDelete(DeleteBehavior.Cascade);

            modelBuilder.Entity<BulletinBoardPage>()
                .HasMany(t => t.Links)
                .WithOne(t => t.BulletinBoardPage)
                .OnDelete(DeleteBehavior.Cascade);

            modelBuilder.Entity<BulletinBoardPage>()
                .HasMany(t => t.Notes)
                .WithOne(t => t.BulletinBoardPage)
                .OnDelete(DeleteBehavior.Cascade);
        }
    }
}
