using Shared.Data.Entities;

namespace PageFetcher.Data.Entities;

/// <summary>
/// Audit record of a single page-fetch operation performed by the page-fetcher-api.
/// Stores the full rendered HTML and extracted plain text for every URL fetched.
/// </summary>
public sealed class PageFetchEntity : BaseEntity
{
    /// <summary>The URL that was requested.</summary>
    public string Url { get; set; } = string.Empty;

    /// <summary>Name of the service that requested the fetch (e.g. <c>cv-matcher-api</c>, <c>cv-search-job</c>).</summary>
    public string CallerService { get; set; } = string.Empty;

    /// <summary>HTTP status code returned by the remote server. <c>null</c> on network failure.</summary>
    public int? HttpStatusCode { get; set; }

    /// <summary>Full rendered HTML as returned by Playwright.</summary>
    public string Html { get; set; } = string.Empty;

    /// <summary>Plain text extracted from the HTML (script/style stripped, whitespace normalised).</summary>
    public string Text { get; set; } = string.Empty;

    /// <summary>Playwright round-trip time in milliseconds.</summary>
    public long DurationMs { get; set; }

    /// <summary><c>true</c> when the page was fetched successfully; <c>false</c> on timeout or network error.</summary>
    public bool Success { get; set; }

    /// <summary>Exception message when <see cref="Success"/> is <c>false</c>.</summary>
    public string? ErrorMessage { get; set; }

    /// <summary>
    /// Optional reference to the <c>cvSearch.JobSearchSessions</c> row that triggered this fetch.
    /// Null for fetches not originating from a job search session (e.g. direct CV-to-job matches).
    /// </summary>
    public string? JobSearchSessionId { get; set; }
}
