using System.Net;

namespace Pilz.Net.Api;

public record class ApiResponse(
    HttpResponseMessage Response)
{
    public HttpStatusCode StatusCode => Response.StatusCode;

    public bool IsOk => (int)StatusCode >= 200 && (int)StatusCode <= 299;

    public void EnsureOk()
    {
        if (!IsOk)
            throw new ApiException("Api return is not ok: " + StatusCode, StatusCode);
    }
}
