using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using PlotLine.Services; namespace PlotLine.Controllers; [Authorize,ResponseCache(NoStore=true,Location=ResponseCacheLocation.None)] public sealed class AiController(IDiscretionaryAi allowance,ICurrentUserService user):Controller { [HttpGet] public async Task Quote(string operation) { if(user.UserId is not int author)return Forbid(); if(string.IsNullOrWhiteSpace(operation)||operation.Length>80)return BadRequest(); var quote=await allowance.Quote(author,operation); return Json(new{allowed=quote.CanExecute,entitled=quote.Entitled,name=quote.Operation?.DisplayName??"AI operation",cost=quote.Operation?.CreditCost,remaining=quote.Allowance.Remaining,renewal=quote.Allowance.PeriodEndUtc,message=quote.Message,upgradeUrl=Url.Action("Subscription","ManageAccount")}); } }