using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace SST.Playground.Models.Mapping
{
    public class EventImageUrlMap : EntityTypeConfiguration<EventImageUrl>
    {
        public EventImageUrlMap()
        {
            // Primary Key
            this.HasKey(t => t.EventImageUrlId);

            // Properties
            this.Property(t => t.Url)
                .IsRequired()
                .HasMaxLength(256);

            this.Property(t => t.Version)
                .IsRequired()
                .IsFixedLength()
                .HasMaxLength(8)
                .IsRowVersion();

            // Table & Column Mappings
            this.ToTable("EventImageUrls");
            this.Property(t => t.EventImageUrlId).HasColumnName("EventImageUrlId");
            this.Property(t => t.EventId).HasColumnName("EventId");
            this.Property(t => t.RecurringEventId).HasColumnName("RecurringEventId");
            this.Property(t => t.Url).HasColumnName("Url");
            this.Property(t => t.Version).HasColumnName("Version");

            // Relationships
            this.HasOptional(t => t.Event)
                .WithMany(t => t.EventImageUrls)
                .HasForeignKey(d => d.EventId);
            this.HasOptional(t => t.RecurringEvent)
                .WithMany(t => t.EventImageUrls)
                .HasForeignKey(d => d.RecurringEventId);

        }
    }
}
