using GB5Shared.DTO.Framework.Login; using GB5Shared.Resource.Response; using GB5Shared.Validation; using WiDAL.CustomCode.LineStation; using WiDAL.DTOs; namespace WiBLL.LineStation; public class LineStationBLL : ILineStationBLL { private readonly ILineStationDAL _dal; private readonly IValidation _validation; public LineStationBLL(ILineStationDAL dal, IValidation validation) { _dal = dal; _validation = validation; } public async Task GetCurrentByLineAsync(int productionLineId, LoginDTO login, CancellationToken ct) => await _dal.GetCurrentByLineAsync(productionLineId, login, ct).ConfigureAwait(false); public async Task GetCurrentByWorkstationAsync(int workstationId, LoginDTO login, CancellationToken ct) => await _dal.GetCurrentByWorkstationAsync(workstationId, login, ct).ConfigureAwait(false); // Append-only: close any existing open membership for the same WS+Line, then insert new row. public async Task SaveLineStationAsync(ProductionLineStationDTO dto, LoginDTO login, CancellationToken ct) { if (dto.ProductionLineId == 0) throw new InvalidOperationException("ProductionLineId is required."); if (dto.WorkstationId == 0) throw new InvalidOperationException("WorkstationId is required."); if (dto.PositionNo == 0) throw new InvalidOperationException("PositionNo must be 1 or greater."); if (dto.EffectiveFrom == default) throw new InvalidOperationException("EffectiveFrom is required."); // Close any currently open row for the same line+workstation combination await _dal.CloseCurrentAsync( dto.ProductionLineId, dto.WorkstationId, dto.EffectiveFrom.AddDays(-1), login, ct).ConfigureAwait(false); // Insert the new open-ended row await _dal.InsertNewAsync(dto, login, ct).ConfigureAwait(false); return SuccessResponse.SaveSuccess; } public async Task> GetByLineId(int lineId,LoginDTO loginDTO,CancellationToken ct) { if (lineId == 0) { throw new ArgumentException( "LineId is required.", nameof(lineId)); } return await _dal .GetByLineId(lineId, loginDTO, ct) .ConfigureAwait(false); } }