using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using MMBLL.MMHead; namespace MMSL.EndPoints.MMHead { // Ported from GB4's MMHead.svc.cs Delete(DocumentId, CancelApplicable) — hard-deletes a // Draft MMHead document and its own detail/charges/schedule/addon/parameter/warranty/lot // rows, and unlinks (not deletes) any other document that referenced it. See MMHeadBLL. // DeleteMMHeadAsync / DeleteMMHeadQB for the exact scope and guard checks. public class DeleteMMHead : BaseEndpoint { private readonly IMMHeadBLL _mmHeadBll; public DeleteMMHead(IMMHeadBLL mmHeadBll) { _mmHeadBll = mmHeadBll; } public override void Configure() { Delete("/MMHead/DeleteMMHead"); AllowAnonymous(); } public record DeleteMMHeadParameters( [property: QueryParam] int DocumentId, [property: FromHeader] string Login ); protected override string? GetCacheKey(DeleteMMHeadParameters req, LoginDTO login) => null; protected override async Task> ExecuteAsync( DeleteMMHeadParameters req, LoginDTO login, CancellationToken ct) { try { var result = await _mmHeadBll.DeleteMMHeadAsync(req.DocumentId, login, ct); return await GB5Shared.ResponseStandard.Response.CreateSuccessResponse(result, GB5Shared.GB5Constant.Constant.CacheKeyLevel.NOT_REQUIRED, login); } catch (ArgumentException ex) { return await GB5Shared.ResponseStandard.Response.CreateExceptionError(ex, GB5Shared.GB5Constant.Constant.CacheKeyLevel.NOT_REQUIRED, login, ex.Message, 400); } catch (InvalidOperationException ex) { return await GB5Shared.ResponseStandard.Response.CreateExceptionError(ex, GB5Shared.GB5Constant.Constant.CacheKeyLevel.NOT_REQUIRED, login, ex.Message, 409); } catch (Exception ex) { return await GB5Shared.ResponseStandard.Response.CreateExceptionError(ex, GB5Shared.GB5Constant.Constant.CacheKeyLevel.NOT_REQUIRED, login, "An unexpected error occurred. Please try again.", 500); } } } }