using AdsTrackingService.Domain.SeedWork;

namespace AdsTrackingService.Domain.AggregatesModel.ConversionAggregate;

/// <summary>
/// EN: Conversion aggregate root - tracks conversion events.
/// VI: Conversion aggregate root - theo dõi sự kiện conversion.
/// </summary>
public class Conversion : Entity, IAggregateRoot
{
    private Guid _advertiserId;
    private Guid _campaignId;
    private Guid _userId;
    private string _conversionType = null!;
    private decimal _conversionValue;
    private string _currency;
    private DateTime _conversionTime;

    public Guid AdvertiserId => _advertiserId;
    public Guid CampaignId => _campaignId;
    public Guid UserId => _userId;
    public string ConversionType => _conversionType;
    public decimal ConversionValue => _conversionValue;
    public string Currency => _currency;
    public DateTime ConversionTime => _conversionTime;

    protected Conversion() 
    { 
        _currency = "VND";
    }

    public Conversion(Guid advertiserId, Guid campaignId, Guid userId, string conversionType, decimal conversionValue, string currency = "VND")
    {
        Id = Guid.NewGuid();
        _advertiserId = advertiserId;
        _campaignId = campaignId;
        _userId = userId;
        _conversionType = conversionType;
        _conversionValue = conversionValue;
        _currency = currency;
        _conversionTime = DateTime.UtcNow;
    }

    public static Conversion Purchase(Guid advertiserId, Guid campaignId, Guid userId, decimal amount) =>
        new(advertiserId, campaignId, userId, "purchase", amount);

    public static Conversion Lead(Guid advertiserId, Guid campaignId, Guid userId) =>
        new(advertiserId, campaignId, userId, "lead", 0);
}
