using CartWise.Domain.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace CartWise.Infrastructure.Data.Configurations;

public class StoreLocationConfiguration : IEntityTypeConfiguration<StoreLocation>
{
    public void Configure(EntityTypeBuilder<StoreLocation> builder)
    {
        builder.HasKey(s => s.StoreLocationId);

        builder.Property(s => s.Name)
            .HasMaxLength(200)
            .IsRequired();

        builder.Property(s => s.ExternalStoreId).HasMaxLength(120);
        builder.Property(s => s.AddressLine1).HasMaxLength(200);
        builder.Property(s => s.AddressLine2).HasMaxLength(200);
        builder.Property(s => s.City).HasMaxLength(120);
        builder.Property(s => s.Region).HasMaxLength(80);
        builder.Property(s => s.PostalCode).HasMaxLength(24);
        builder.Property(s => s.CountryCode).HasMaxLength(2);

        builder.HasOne<Retailer>()
            .WithMany()
            .HasForeignKey(s => s.RetailerId)
            .OnDelete(DeleteBehavior.Cascade);

        builder.HasIndex(s => s.RetailerId);
    }
}
