# Product Management

The `productManager` provides methods to create and manage products in the Galliun Payment Protocol.

## Creating Products

```typescript
const { resp, productObjChange } = await client.productManager.createProduct(
	coinType, // e.g., "0x2::sui::SUI"
	name, // Product name
	description, // Product description
	price, // Price in smallest unit
	quantity, // Initial quantity
	{
		dryRun, // Optional: Simulate transaction
		sender, // Optional: Override default sender
	},
);
```

### Response

```typescript
interface ProductResponse {
	resp: SuiTransactionBlockResponse;
	productObjChange: {
		id: string;
		type: string;
		// ... other product properties
	};
}
```

## Managing Products

### Buy Product

```typescript
const resp = await client.productManager.buyProduct(
	coinType, // Token type to pay with
	productId, // ID of the product to buy
	price, // Price to pay
	{
		dryRun, // Optional: Simulate transaction
		sender, // Optional: Override default sender
	},
);
```

### Update Product Info

```typescript
const resp = await client.productManager.updateProductInfo(
	coinType, // Token type
	productId, // ID of the product to update
	name, // New name
	description, // New description
	price, // New price
	{
		dryRun, // Optional: Simulate transaction
		sender, // Optional: Override default sender
	},
);
```

### Manage Quantity

#### Increase Quantity

```typescript
const resp = await client.productManager.increaseQuantity(
	productId, // ID of the product
	amount, // Amount to increase
	{
		dryRun, // Optional: Simulate transaction
		sender, // Optional: Override default sender
	},
);
```

#### Decrease Quantity

```typescript
const resp = await client.productManager.decreaseQuantity(
	productId, // ID of the product
	amount, // Amount to decrease
	{
		dryRun, // Optional: Simulate transaction
		sender, // Optional: Override default sender
	},
);
```

## Fetching Products

### Fetch Single Product

```typescript
const product = await client.productManager.fetchProduct(productId);
```

### Fetch Multiple Products

```typescript
const products = await client.productManager.fetchProducts([productId1, productId2]);
```

## Product Object

The SDK returns products in this format:

```typescript
interface ProductObj {
	id: string;
	name: string;
	description: string;
	price: bigint;
	coin_type: string;
	creator: string;
	creation_time: number;
	quantity: bigint;
	sold: bigint;
	is_available: boolean;
}
```

## Error Handling

Handle specific product management errors:

```typescript
try {
	await client.productManager.buyProduct(/* ... */);
} catch (error) {
	switch (error.code) {
		case 'UNSUPPORTED_COIN':
			// Handle unsupported coin type
			break;
		case 'INSUFFICIENT_BALANCE':
			// Handle insufficient balance
			break;
		case 'OUT_OF_STOCK':
			// Handle out of stock
			break;
		case 'PERMISSION_DENIED':
			// Handle permission issues
			break;
		default:
		// Handle other errors
	}
}
```

## Common Use Cases

1. Create and Track Product:

```typescript
// Create product
const { productObjChange } = await client.productManager.createProduct(/* ... */);
const productId = productObjChange.id;

// Monitor inventory
const product = await client.productManager.fetchProduct(productId);
console.log('Available:', product.quantity - product.sold);
```

2. Update Product with Price Change:

```typescript
await client.productManager.updateProductInfo(
	coinType,
	productId,
	product.name, // Keep existing name
	product.description, // Keep existing description
	newPrice, // Update price only
);
```
