package main

import (
	"fmt"
	"os"

	"license-sdk-example/licenseclient"
)

const (
	baseURL      = "https://YOUR-SERVER"            // your license server (https:// only)
	product      = "YOUR_PRODUCT_ID"                // shown on the product's page in your dashboard
	publicKeyB64 = "PASTE_PUBLIC_KEY_FROM_THE_DOCS" // public - not a secret
)

func main() {
	if len(os.Args) < 2 {
		fmt.Fprintln(os.Stderr, "usage: example <license-key>")
		os.Exit(1)
	}
	key := os.Args[1]

	client, err := licenseclient.New(baseURL, product, publicKeyB64)
	if err != nil {
		fmt.Fprintln(os.Stderr, "client setup failed:", err)
		os.Exit(1)
	}

	result := client.Check(key)
	if result.Valid {
		note := ""
		if result.FromOfflineCache {
			note = " (offline grace period)"
		}
		fmt.Printf("License OK - status=%s, expiresAt=%s%s\n", result.Status, result.ExpiresAt, note)
	} else {
		fmt.Println("License invalid:", result.Reason)
		os.Exit(1)
	}
}
