﻿using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Yamd.WebService;

namespace WebService.Migrations
{
    [DbContext(typeof(AppDataContext))]
    [Migration("20170305004241_Create")]
    partial class Create
    {
        protected override void BuildTargetModel(ModelBuilder modelBuilder)
        {
            modelBuilder
                .HasAnnotation("ProductVersion", "1.1.0-rtm-22752");

            modelBuilder.Entity("Yamd.WebService.Entity.MediaFormat", b =>
                {
                    b.Property<long>("Id")
                        .ValueGeneratedOnAdd();

                    b.Property<string>("Name");

                    b.HasKey("Id");

                    b.ToTable("MediaFormats");
                });

            modelBuilder.Entity("Yamd.WebService.Entity.Movie", b =>
                {
                    b.Property<long>("Id")
                        .ValueGeneratedOnAdd();

                    b.Property<long>("FormatId");

                    b.Property<string>("Name");

                    b.Property<long>("Year");

                    b.HasKey("Id");

                    b.HasIndex("FormatId");

                    b.ToTable("Movies");
                });

            modelBuilder.Entity("Yamd.WebService.Entity.MovieScreenshot", b =>
                {
                    b.Property<long>("Id")
                        .ValueGeneratedOnAdd();

                    b.Property<string>("FileExt");

                    b.Property<string>("FileId");

                    b.Property<long?>("MovieId");

                    b.HasKey("Id");

                    b.HasIndex("MovieId");

                    b.ToTable("MovieScreenshots");
                });

            modelBuilder.Entity("Yamd.WebService.Entity.User", b =>
                {
                    b.Property<long>("Id")
                        .ValueGeneratedOnAdd();

                    b.Property<string>("DisplayName");

                    b.Property<string>("Name")
                        .IsRequired();

                    b.Property<string>("PasswordHash");

                    b.HasKey("Id");

                    b.HasAlternateKey("Name");

                    b.ToTable("Users");
                });

            modelBuilder.Entity("Yamd.WebService.Entity.UserPermission", b =>
                {
                    b.Property<long>("Id")
                        .ValueGeneratedOnAdd();

                    b.Property<long>("PermissionId");

                    b.Property<long>("UserId");

                    b.HasKey("Id");

                    b.HasIndex("UserId");

                    b.ToTable("UserPermissions");
                });

            modelBuilder.Entity("Yamd.WebService.Entity.UserSession", b =>
                {
                    b.Property<long>("Id")
                        .ValueGeneratedOnAdd();

                    b.Property<DateTime>("Expiration");

                    b.Property<string>("Token");

                    b.Property<long>("UserId");

                    b.HasKey("Id");

                    b.HasIndex("UserId");

                    b.ToTable("UserSessions");
                });

            modelBuilder.Entity("Yamd.WebService.Entity.Movie", b =>
                {
                    b.HasOne("Yamd.WebService.Entity.MediaFormat", "Format")
                        .WithMany()
                        .HasForeignKey("FormatId")
                        .OnDelete(DeleteBehavior.Cascade);
                });

            modelBuilder.Entity("Yamd.WebService.Entity.MovieScreenshot", b =>
                {
                    b.HasOne("Yamd.WebService.Entity.Movie")
                        .WithMany("Screenshots")
                        .HasForeignKey("MovieId");
                });

            modelBuilder.Entity("Yamd.WebService.Entity.UserPermission", b =>
                {
                    b.HasOne("Yamd.WebService.Entity.User")
                        .WithMany("Permissions")
                        .HasForeignKey("UserId")
                        .OnDelete(DeleteBehavior.Cascade);
                });

            modelBuilder.Entity("Yamd.WebService.Entity.UserSession", b =>
                {
                    b.HasOne("Yamd.WebService.Entity.User", "User")
                        .WithMany()
                        .HasForeignKey("UserId")
                        .OnDelete(DeleteBehavior.Cascade);
                });
        }
    }
}
