using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using isnd.Data.Catalog;
using Newtonsoft.Json;

namespace isnd.Data
{
    public class PackageVersion
    {
        [Required]
        [ForeignKey("Package")]
        [StringLength(1024)]
        public string PackageId { get; set; }

        [Required]
        public int Major { get; set; }
        
        [Required]
        public int Minor { get; set; }
        
        [Required]
        public int Patch { get; set; }

        [StringLength(256)]
        [Required]
        public string FullString { get; set; }
        public bool IsPrerelease { get; set; }

        [StringLength(256)]
        public string Type { get; set; }

        [JsonIgnore]
        public virtual Package Package { get; set; }

        [Required][JsonIgnore]
        [ForeignKey("LatestCommit")]
        public long CommitNId { get; set ; }

        [NotMapped]

        public string CommitId { get => CommitNId.ToString(); }


        public virtual Commit LatestCommit{ get; set; }
        public string NugetLink => $"/package/{PackageId}/{FullString}/{PackageId}-{FullString}.nupkg";
        public string NuspecLink => $"/package/{PackageId}/{FullString}/{PackageId}-{FullString}.nuspec";

    }
}