using AdsAnalyticsService.Domain.SeedWork;

namespace AdsAnalyticsService.Domain.AggregatesModel.ReportAggregate;

/// <summary>
/// EN: Report aggregate root - scheduled or custom reports.
/// VI: Report aggregate root - báo cáo theo lịch hoặc tùy chỉnh.
/// </summary>
public class Report : Entity, IAggregateRoot
{
    private Guid _advertiserId;
    private string _name = null!;
    private ReportType _reportType;
    private DateTime _startDate;
    private DateTime _endDate;
    private ReportStatus _status;
    private string? _dataJson;

    public Guid AdvertiserId => _advertiserId;
    public string Name => _name;
    public ReportType ReportType => _reportType;
    public DateTime StartDate => _startDate;
    public DateTime EndDate => _endDate;
    public ReportStatus Status => _status;
    public string? DataJson => _dataJson;
    public DateTime CreatedAt { get; private set; }

    protected Report() { }

    public Report(Guid advertiserId, string name, ReportType reportType, DateTime startDate, DateTime endDate)
    {
        Id = Guid.NewGuid();
        _advertiserId = advertiserId;
        _name = name;
        _reportType = reportType;
        _startDate = startDate;
        _endDate = endDate;
        _status = ReportStatus.Pending;
        CreatedAt = DateTime.UtcNow;
    }

    public void MarkAsProcessing() => _status = ReportStatus.Processing;
    public void Complete(string dataJson)
    {
        _dataJson = dataJson;
        _status = ReportStatus.Completed;
    }
    public void Fail() => _status = ReportStatus.Failed;
}

public enum ReportType
{
    Campaign = 1,
    AdSet = 2,
    Ad = 3,
    Audience = 4
}

public enum ReportStatus
{
    Pending = 1,
    Processing = 2,
    Completed = 3,
    Failed = 4
}
