using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using PartnerBLL.ClientDetail; using static GB5Shared.GB5Constant.Constant; namespace PartnerSL.EndPoints.ClientDetail { // Fills a confirmed gap: no endpoint anywhere in the codebase creates MCLIENTDETAILS // rows (every other reference is SELECT/UPDATE/DDL only). ClientId/ClientSiteId must // already exist as real identities (e.g. via /lic/Onboarding.svc/OnboardClient, which // provisions the matching MSERVERCONFIG row) — this only creates the white-labeling // side of the row so AssignPartnerProduct has something to update afterward. The 7 // CRM-assignment columns MCLIENTDETAILS also carries (SalesInChargeId, etc.) are // outside Partner's concern and are seeded with -1 (this schema's "not set" sentinel). public class CreateClientDetail : BaseEndpoint> { private readonly IClientDetailBLL _bll; public CreateClientDetail(IClientDetailBLL bll) => _bll = bll; public override void Configure() { Post("/ClientDetail/CreateClientDetail"); AllowAnonymous(); } public record CreateClientDetailParameters( [property: FromHeader] string Login, [property: QueryParam] int ClientId, [property: QueryParam] int ClientSiteId ); protected override string? GetCacheKey(CreateClientDetailParameters req, LoginDTO loginDTO) => null; protected override async Task> ExecuteAsync( CreateClientDetailParameters req, LoginDTO loginDTO, CancellationToken ct) { try { var result = await _bll.CreateClientDetail(req.ClientId, req.ClientSiteId); 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); } } } }