using AmpDAL.DTO.ApiInterface; using AmpDAL.Query.ApiArtifact; using AmpDAL.Query.ApiInterface; using GB5Shared.DTO.Framework.Criteria; using GB5Shared.DTO.Framework.Login; using GB5Shared.QueryExecutor; namespace AmpDAL.CustomCode.ApiInterface; public class ApiInterfaceDAL(IQueryExecutor _qe) : IApiInterfaceDAL { public async Task GetInterfaceAsync(long ApiInterfaceId, int tenantId, LoginDTO login, CancellationToken ct) => await _qe.QuerySingleAsync( login, ApiInterfaceQB.GET_INTERFACE, new { ApiInterfaceId = ApiInterfaceId, TenantId = tenantId }).ConfigureAwait(false); public async Task> GetInterfaceListAsync(CriteriaDTO criteriaDTO, LoginDTO login, CancellationToken ct) { var result = await _qe.QueryAsync( login, ApiInterfaceQB.GET_INTERFACE_LIST, new { TenantId = login.ClientId }).ConfigureAwait(false); return result.ToList(); } public async Task SaveInterfaceAsync(ApiInterfaceSaveDTO dto, LoginDTO login, CancellationToken ct) { dto.TenantId = login.ClientId; dto.CreatedById = login.UserId; dto.ModifiedById = login.UserId; return await _qe.ExecuteScalarAsync( login, ApiInterfaceQB.SAVE_INTERFACE, new { dto.ApiInterfaceId, dto.TenantId, dto.ApiId, dto.ApiVersionId, dto.InterfaceType, // ✅ NEW FIELDS dto.InterfaceName, dto.SpecType, dto.Method, dto.ApiPath, dto.InterfaceDescription, dto.SpecLocation, dto.ContentHash, dto.ParsedSuccessfully, dto.LastParsedAt, dto.Source, dto.Remarks, dto.SortOrder, dto.Status, dto.Version, dto.SourceType, dto.CreatedById, dto.CreatedOn, dto.ModifiedById, dto.ModifiedOn }).ConfigureAwait(false); } public async Task UpdateInterfaceAsync(ApiInterfaceSaveDTO dto, LoginDTO login, CancellationToken ct) { dto.TenantId = login.ClientId; dto.ModifiedById = login.UserId; await _qe.ExecuteAsync( login, ApiInterfaceQB.UPDATE_INTERFACE, new { dto.ApiInterfaceId, dto.ApiVersionId, dto.InterfaceType, // ✅ NEW FIELDS dto.InterfaceName, dto.SpecType, dto.Method, dto.ApiPath, dto.InterfaceDescription, dto.SpecLocation, dto.ContentHash, dto.ParsedSuccessfully, dto.LastParsedAt, dto.Source, dto.Remarks, dto.SortOrder, dto.Status, dto.Version, dto.SourceType, dto.ModifiedById, dto.ModifiedOn }).ConfigureAwait(false); return dto.ApiInterfaceId; } public async Task UpdateParseResultAsync(long apiInterfaceId, bool parsedSuccessfully, string? contentHash, LoginDTO login, CancellationToken ct) { await _qe.ExecuteAsync( login, ApiInterfaceQB.UPDATE_PARSE_RESULT, new { ApiInterfaceId = apiInterfaceId, ParsedSuccessfully = parsedSuccessfully, ContentHash = contentHash, ModifiedById = login.UserId }).ConfigureAwait(false); } public async Task> GetInterfaceSelectListAsync(CriteriaDTO criteriaDTO, LoginDTO login, CancellationToken ct) { var result = await _qe.QueryAsync( login, ApiInterfaceQB.GET_INTERFACE_SELECT_LIST, new { TenantId = login.ClientId }).ConfigureAwait(false); return result.ToList(); } public async Task> GetPagedInterfaceList(int firstNumber, int maxResult, CriteriaDTO criteriaDTO, LoginDTO login, CancellationToken ct) { var result = await _qe.QueryAsync( login, ApiInterfaceQB.GET_INTERFACE_LIST_PAGED, new { TenantId = login.ClientId, FirstNumber = firstNumber, MaxResult = maxResult }).ConfigureAwait(false); return result.ToList(); } public async Task DeleteById(int apiInterfaceId, LoginDTO login, CancellationToken ct) => await _qe.ExecuteAsync( login, ApiInterfaceQB.DELETE_INTERFACE, new { ApiInterfaceId = apiInterfaceId, TenantId = login.ClientId }).ConfigureAwait(false); }