using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace Database.Models
{
    public class Build : BaseEntity
    {
        public int ProjectId { get; set; }
        
        [Required]
        [MaxLength(100)]
        public string BuildNumber { get; set; } = string.Empty;
        
        [Required]
        [MaxLength(50)]
        public string Status { get; set; } = "Unknown"; // Success, Failure, Exception, Cancelled, Unknown
        
        public DateTime StartTime { get; set; }
        
        public DateTime? EndTime { get; set; }
        
        public string? LogPath { get; set; }
        
        public string? ArtifactPath { get; set; }
        
        public TimeSpan? Duration => EndTime?.Subtract(StartTime);
        
        // Navigation properties
        [ForeignKey(nameof(ProjectId))]
        public Project Project { get; set; } = null!;
        
        public ICollection<BuildCommit> Commits { get; set; } = new List<BuildCommit>();
    }
}