using AfRApay.Web.Backend;
using AfRApay.Web.Backend.Tables;
using LinqToDB;
using Microsoft.AspNetCore.Mvc;

namespace AfRApay.Web.Controllers;

[ApiController, Route("/api/card/balance")]
public class CardBalance : Controller {
	[HttpGet]
	public string Get([FromQuery] string card) {
		var db = new Database.DbConn();
		if (db.Cards.Any(p => p.CardId == card)) {
			var userId = db.Cards.First(p => p.CardId == card).UserId;
			var user   = db.Users.First(p => p.Id == userId);
			return $"S:{user.Nickname}:{user.Balance:N2}";
		}

		return "E:Unknown card.";
	}
}
