defmodule Mix.Tasks.SoftPos.Revoke.Client do @moduledoc """ Revokes (deletes) an OAuth2.0 client for SoftPOS API. ## Usage mix soft_pos.revoke.client ## Arguments * client_id - The client ID (uid) to revoke ## Example mix soft_pos.revoke.client "softpos_abc123" This will delete the client application. Existing tokens will be invalidated. """ use Mix.Task alias DaProductApp.SoftPos.OauthApplications @shortdoc "Revoke (delete) an OAuth client" @impl Mix.Task def run([client_uid]) do Mix.Task.run("app.start") case OauthApplications.get_by_uid(client_uid) do nil -> Mix.shell().error("Client not found: #{client_uid}") client -> case OauthApplications.delete_application(client) do {:ok, _deleted_client} -> Mix.shell().info(""" ✅ Client Revoked Successfully! Client ID: #{client_uid} Name: #{client.name} The client has been deleted and all associated tokens have been revoked. """) {:error, changeset} -> Mix.shell().error("Failed to revoke client:") Mix.shell().error(inspect(changeset.errors)) end end end def run(_) do Mix.shell().error(""" Usage: mix soft_pos.revoke.client Example: mix soft_pos.revoke.client "softpos_abc123" """) end end