using Tiku.Api.Contracts;
using Tiku.Application.Commerce;
using Tiku.Application.Security;

namespace Tiku.Api.Controllers;

public sealed class CommerceAdminActorResolver(
    ICurrentUser currentUser,
    ITenantContext currentTenant)
{
    internal CommerceAdminActor Resolve()
    {
        if (currentTenant.TenantId is null || currentUser.UserId is null)
            throw new CommerceException("Tenant commerce actor was not resolved.", "tenant_admin_access_denied");

        return new CommerceAdminActor(currentTenant.TenantId.Value, currentUser.UserId.Value);
    }

    internal CommerceAdminQuery ToQuery(TenantCommerceQueryDto query)
    {
        return new CommerceAdminQuery(query.Provider, query.Status, query.Limit);
    }

    internal TenantPointQuery ToPointQuery(TenantCommerceQueryDto query)
    {
        return new TenantPointQuery(query.Status, query.Limit, query.UserId, query.RegionId);
    }
}
