using System.Text.Json;
using Microsoft.AspNetCore.Mvc;
using WebClientTpos.Server.Infrastructure;
namespace WebClientTpos.Server.Controllers;
///
/// EN: Shop management controller — proxies to MerchantService for shop CRUD, settings, stats, devices.
/// VI: Controller quản lý cửa hàng — proxy đến MerchantService cho CRUD shop, settings, stats, devices.
///
[ApiController]
[Route("api/bff")]
public class ShopController : ControllerBase
{
private readonly HttpClient _merchant;
public ShopController(IHttpClientFactory httpClientFactory)
{
_merchant = httpClientFactory.CreateClient("MerchantService");
}
///
/// EN: Get all shops belonging to the current merchant.
/// VI: Lấy tất cả cửa hàng thuộc merchant hiện tại.
///
[HttpGet("shops")]
public Task GetShops() =>
_merchant.GetAsync("/api/v1/shops").ProxyAsync();
///
/// EN: Get shop by ID.
/// VI: Lấy cửa hàng theo ID.
///
[HttpGet("shops/{shopId:guid}")]
public Task GetShopById(Guid shopId) =>
_merchant.GetAsync($"/api/v1/shops/{shopId}").ProxyAsync();
///
/// EN: Update shop info.
/// VI: Cập nhật thông tin cửa hàng.
///
[HttpPut("shops/{shopId:guid}")]
public Task UpdateShop(Guid shopId, [FromBody] JsonElement body) =>
_merchant.PutAsJsonAsync($"/api/v1/shops/{shopId}", body).ProxyAsync();
///
/// EN: Get shop settings.
/// VI: Lấy cài đặt cửa hàng.
///
[HttpGet("shops/{shopId:guid}/settings")]
public Task GetShopSettings(Guid shopId) =>
_merchant.GetAsync($"/api/v1/shops/{shopId}/settings").ProxyAsync();
///
/// EN: Update shop settings.
/// VI: Cập nhật cài đặt cửa hàng.
///
[HttpPut("shops/{shopId:guid}/settings")]
public Task UpdateShopSettings(Guid shopId, [FromBody] JsonElement body) =>
_merchant.PutAsJsonAsync($"/api/v1/shops/{shopId}/settings", body).ProxyAsync();
///
/// EN: Get aggregated stats per shop.
/// VI: Lấy thống kê tổng hợp theo shop.
///
[HttpGet("shops/stats")]
public Task GetShopStats() =>
_merchant.GetAsync("/api/v1/shops/stats").ProxyAsync();
///
/// EN: Get device tokens registered for this merchant's staff.
/// VI: Lấy danh sách device token đã đăng ký cho nhân viên của merchant.
///
[HttpGet("devices")]
public Task GetDevices() =>
_merchant.GetAsync("/api/v1/devices").ProxyAsync();
}