using Data.SeaHavenIndustries; using SeaHaven.DataServices.Interfaces; using SeaHaven.Services.DTOs; using SeaHaven.Services.Exceptions; using SeaHaven.Services.Helpers; using SeaHaven.Services.Interfaces; namespace SeaHaven.Services.Implementation { public class WorkOrderCommentService : IWorkOrderCommentService { private readonly IWorkOrderDetailDataService _detailData; private readonly ICommentDataService _commentData; public WorkOrderCommentService( IWorkOrderDetailDataService detailData, ICommentDataService commentData) { _detailData = detailData; _commentData = commentData; } public async Task?> GetCommentsAsync(int workOrderId) { if (!await _detailData.ExistsAsync(workOrderId)) return null; var comments = await _detailData.GetCommentsAsync(workOrderId); return WorkOrderCommentProjection.ToDtos(comments); } public async Task AddCommentAsync( int workOrderId, WorkOrderCommentCreateDto request, string? actorId, string? documentUrl = null) { if (!await _detailData.ExistsAsync(workOrderId)) throw new WorkOrderBoardValidationException("NotFound", "Work order not found."); if (string.IsNullOrWhiteSpace(request.Text)) throw new WorkOrderBoardValidationException("InvalidValue", "Comment text is required."); var comment = new Comments { WorkerOrderId = workOrderId, UserId = actorId, Commenttext = request.Text.Trim(), CommentType = "General", RecordType = "WorkOrder", Documents = documentUrl, CreatedDate = DateTime.UtcNow }; var saved = await _commentData.AddAsync(comment); return WorkOrderCommentProjection.ToDto(saved); } } }