using System;

namespace JobTrackerApi.Models
{
    /// <summary>
    /// A job opportunity — the role as the employer posted it, independent of whether the user
    /// has applied. Separated from <see cref="JobApplication"/> (the user's pursuit of a job) so
    /// that:
    ///   - a job can be tracked before it is applied to (see JobPipeline's Prospect stages), and
    ///   - applying twice to the same role does not duplicate the whole job description.
    ///
    /// Introduced in Phase 0 (2026-07-17). New applications dual-write this opportunity row while
    /// <see cref="JobApplication"/> remains the read source during the incremental cutover.
    ///
    /// See docs/decisions/ADR-002-job-application-model.md.
    /// </summary>
    public class Job
    {
        public int Id { get; set; }
        public string? OwnerUserId { get; set; }

        public int CompanyId { get; set; }
        public Company Company { get; set; } = null!;

        public string JobTitle { get; set; } = "";
        public string? Location { get; set; }
        public string? JobUrl { get; set; }

        // Imported job content.
        public string? Description { get; set; }
        public string? TranslatedDescription { get; set; }
        public string? DescriptionLanguage { get; set; } // "en", "no", ...
        public string? ShortSummary { get; set; }
        public string? Tags { get; set; } // JSON array string, e.g. ["Azure","Docker"]
        public DateTime? Deadline { get; set; }

        // Structured salary; the free-text Salary field is kept for display/back-compat.
        public string? Salary { get; set; }
        public decimal? SalaryMin { get; set; }
        public decimal? SalaryMax { get; set; }
        public string? SalaryCurrency { get; set; } // e.g. "NOK", "GBP", "EUR"
        public string? SalaryPeriod { get; set; }   // "year" | "month" | "hour"

        // Where this job came from. Market is data, not an assumption: Jobjakt is Norway-first
        // but must not hardcode Norway, so country travels with the job rather than being
        // implied by the importer. Null = unknown/manually entered.
        public string? Source { get; set; }      // e.g. "finn", "nav", "linkedin", "manual"
        public string? CountryCode { get; set; } // ISO 3166-1 alpha-2, e.g. "NO", "GB"

        /// <summary>When the user first captured this opportunity.</summary>
        public DateTime SavedAt { get; set; } = DateTime.UtcNow;

        public List<JobApplication> Applications { get; set; } = new();
    }
}
