using AccountsBLL.Voucher; using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using static GB5Shared.GB5Constant.Constant; namespace AccountsSL.EndPoints.Voucher { // Faithful port of GB4 Voucher.svc's DELETE /?VoucherId=&CancelApplicable= operation. // CancelApplicable: 0 = hard delete, 1 = soft cancel (STATUS=2). See VoucherBLL.DeleteVoucherAsync // for the full behavior and the scope this port deliberately excludes. public class DeleteVoucher : BaseEndpoint> { private readonly IVoucherBLL _VoucherBLL; public DeleteVoucher(IVoucherBLL voucherBLL) { _VoucherBLL = voucherBLL; } public override void Configure() { Delete("/Voucher/DeleteVoucher"); AllowAnonymous(); } // CancelApplicable defaults to 0 (hard delete) when omitted from the query string, matching // GB4's own default parameter (int CancelApplicable = 0) — the "Delete" button in GB4's UI // calls this endpoint with no CancelApplicable at all, relying on that default. public record DeleteVoucherParameters( [property: FromHeader] string Login, [property: QueryParam] int VoucherId, [property: QueryParam] int CancelApplicable = 0 ); protected override string? GetCacheKey(DeleteVoucherParameters req, LoginDTO loginDTO) => null; protected override async Task> ExecuteAsync(DeleteVoucherParameters req, LoginDTO LoginDTO, CancellationToken ct) { try { var Result = await _VoucherBLL.DeleteVoucherAsync(req.VoucherId, req.CancelApplicable, LoginDTO!); return await GB5Shared.ResponseStandard.Response.CreateSuccessResponse(Result, CacheKeyLevel.NOT_REQUIRED, LoginDTO); } catch (Exception ex) { return await GB5Shared.ResponseStandard.Response.CreateExceptionError(ex, CacheKeyLevel.NOT_REQUIRED, LoginDTO, ex.Message, 500); } } } }