using FluentMigrator;
using FluentMigrator.Builders.Create.Table;
using Nop.Data.Mapping.Builders;
using Nop.Plugin.Misc.AuctionPlugin.Domains.Entities;
using Nop.Data.Extensions;
using System.Data;
using Nop.Core.Domain.Catalog;
using Nop.Core.Domain.Common;
using Nop.Data.Mapping;

namespace Nop.Plugin.Misc.AuctionPlugin.Mapping.Builders;

public class AuctionBuilder : NopEntityBuilder<Auction>
{
    #region Methods

    /// <summary>
    /// Apply entity configuration
    /// </summary>
    /// <param name="table">Create table expression builder</param>
    public override void MapEntity(CreateTableExpressionBuilder table)
    {
        table.WithColumn(nameof(Auction.Id)).AsInt32().PrimaryKey().Identity()

            //.WithColumn(nameof(Auction.AuctionId)).AsInt32().ForeignKey<Auction>(onDelete: Rule.Cascade) //Rule.Cascade??
            //.WithColumn(nameof(Auction.ProductId)).AsInt32().ForeignKey<Product>(onDelete: Rule.Cascade) //Rule.Cascade??

            .WithColumn(nameof(Auction.AuctionType)).AsByte().NotNullable()
            
            //.WithColumn(nameof(Auction.StartingPrice)).AsInt32().NotNullable()
            //.WithColumn(nameof(Auction.BidPrice)).AsInt32().NotNullable()
            //.WithColumn(nameof(Auction.BidAmount)).AsInt32().NotNullable().WithDefaultValue(1)
            .WithColumn(nameof(Auction.Created)).AsDateTime().NotNullable()
            .WithColumn(nameof(Auction.Modified)).AsDateTime().NotNullable().WithDefault(SystemMethods.CurrentUTCDateTime);
    }

    #endregion
}