
Develop a WordPress admin-only WooCommerce plugin that syncs products from external APIs into WooCommerce.
## 1. Dashboard
The dashboard serves as the central hub for monitoring sync activities and statuses.

### **Requirements:**
*   **Sync Activity Log:**
    *   Display a table of recent sync activities.
    *   **Columns:** Supplier Name, Status, Start Time, End Time, Items Synced, Errors.
    *   **Search/Filter:** Search by Supplier Name.
    *   **Detailed View:** Expand rows to see request/response details (JSON format) and specific error messages.
*   **Order Sync Logs:** (If applicable/premium)
    *   Display a table of order sync events.
    *   **Columns:** Order ID, Status, Sync Time, Response status.
    *   **Detailed View:** Request and Response JSON payload inspection.
*   **Quick Actions:**
    *   **Start Sync:** Trigger a manual sync for a specific supplier.
    *   **Pause/Resume:** Control ongoing sync processes.
    *   **Abort:** Forcefully stop a stuck or unwanted sync process.
    *   **Delete:** Remove sync history or logs.
*   **Statistics/Overview:**
    *   Summary cards showing total products synced, active suppliers, and recent error counts.

## 2. Supplier Management
Allows users to manage multiple external API connections (Suppliers).

### **Requirements:**
*   **Supplier List:**
    *   Display all configured suppliers.
    *   Show status (Active/Inactive), Last Sync time, Next Scheduled Sync.
*   **CRUD Operations:**
    *   **Add New Supplier:** Wizard or tabbed interface to configure a new connection.
    *   **Edit Supplier:** Modify existing configurations.
    *   **Delete Supplier:** Remove connection and associated settings.

## 3. Supplier Configuration
The core functionality is divided into modular tabs for configuring the API connection and data mapping.

### **A. Authorization**
Configure how the plugin authenticates with the external API. The UI must dynamically change based on the selected **Auth Type**.

#### **Supported Auth Types & Fields:**

1.  **No Auth:**
    *   *Usage*: For public APIs requiring no credentials.
    *   *Fields*: None.

2.  **Basic Auth:**
    *   *Usage*: Standard Username/Password authentication (Base64 encoded).
    *   *Fields*:
        *   **Username** (Required)
        *   **Password** (Required)
        *   **Auth Header Name** (Default: `Authorization`)

3.  **Bearer Token:**
    *   *Usage*: Simple token-based authentication.
    *   *Fields*:
        *   **Token** (Required)
        *   **Token Type** (Default: `Bearer`)
        *   **Auth Header Name** (Default: `Authorization`)

4.  **API Key:**
    *   *Usage*: Key-Secret pair, often used in headers or query params.
    *   *Fields*:
        *   **Key** (Required)
        *   **Secret** (Required)

5.  **OAuth 2.0:**
    *   *Usage*: Complex authentication flows.
    *   *Grant Types Supported*: `Client Credentials`, `Password`.
    *   *Common Fields*:
        *   **Access Token URL** (Required, Valid URL)
        *   **Client ID** (Required)
        *   **Client Secret** (Required)
        *   **Client Credentials Type**: Checkbox/Select for `Header` or `Body` (Required).
        *   **Auth Header Name** (Default: `Authorization`)
    *   *Conditional Fields*:
        *   *If Grant Type = Password*:
            *   **Username** (Required)
            *   **Password** (Required)

6.  **Custom Auth:**
    *   *Usage*: For non-standard flows requiring multiple requests.
    *   *Structure*: Separated into **Request Settings** and **Response Settings** tabs.
    *   **Request Settings Tab**:
        *   **URL Method**: GET, POST, PUT (Default: GET).
        *   **URL** (Required, Valid URL).
        *   **Headers**: Dynamic Key-Value pair list (Add/Remove rows).
        *   **Body Type**: `x-www-form-urlencoded` or `Raw (JSON)`.
        *   *If Body Type = JSON*:
            *   **JSON Body**: Text area for raw JSON input (Validated).
        *   *If Body Type = Form*:
            *   **Body Fields**: Dynamic Key-Value pair list.
        *   **Custom Auth Header**: Name of the header to store the received token (Required).
    *   **Response Settings Tab**:
        *   **Token Key**: JSON path to extract the token from response.
        *   **Token Expiry**: Time in seconds.
        *   **Token Type**: Prefix (e.g., `Bearer`).

### **B. API Configuration**
Define the endpoints for fetching data.
*   **Endpoint Definition:**
    *   **Connection Name:** Human-readable name.
    *   **Method:** GET, POST, PUT, etc.
    *   **API URL:** The endpoint URL.
*   **Settings:**
    *   **Auth Enabled:** Toggle to include the configured authorization headers.
    *   **Is Primary:** Designate this endpoint as the main source for product data.
    *   **Resource Type:** Specify if this API fetches **Products** or **Orders**.

### **C. Attribute Mapping**
Map data from the API response to WooCommerce product fields.
*   **Scopes:**
    *   **Parent Product:** Mapping for the main product data.
    *   **Variant Product:** Mapping for variations (if variable products are supported).

#### **1. Core Fields Mapping**
Map essential WooCommerce fields.
*   **UI Structure:** List of WC fields with mapping options.
*   **Common Mapping Options:**
    *   **WooCommerce Attribute:** Read-only label (e.g., "Name", "SKU").
    *   **API Source:** Dropdown to select which API endpoint provides this data.
    *   **Supplier Attribute:** Input for JSON path/key (e.g., `data.items.sku`).
    *   **Sync Options:**
        *   *Add During Sync*: Toggle (Create new).
        *   *Update During Sync*: Toggle (Overwrite existing).
*   **Special Logic per Field:**
    *   **Images:**
        *   **Image Src Attribute:** JSON path to image URL.
        *   **Image Pre Path:** String to prepend (e.g., for relative URLs).
    *   **Regular/Sale Price:**
        *   **Price Margin Config:**
            *   *Operator*: `+`, `-`, `*`, `%`
            *   *Amount*: Value to apply.
        *   **Tier Pricing** (Regular Price only):
            *   *Format Type*: Key-Value pair or specific structure.
            *   *Base Path*: JSON path to tier data.
    *   **Unique Product Identifier:**
        *   Special field (Meta Key) used to identify products uniquely across syncs (e.g., `_supplier_id`).

#### **2. Attributes / Taxonomy / Custom Fields**
*   **Attributes:**
    *   **Map as Global**: Checkbox to create global WC attributes vs local product attributes.
*   **Taxonomies:**
    *   **Categories**: Option to "Fetch from Other API" (Separate API call for category tree).
    *   **Brands**: Option for "Brand Image Config".
*   **Custom Fields (Meta):**
    *   Map any API value to a custom `_postmeta` key.

### **D. Sync Settings**
Configure how and when the synchronization occurs.

#### **1. Data Sync Schedule**
*   **Schedule Name:** Identifier.
*   **Fields:** Multi-select (Parent/Variant fields).
*   **Timezone:** Select timezone.
*   **Timing:** Start Date, Start Time.
*   **Recurrence:** Interval (Value) + Frequency (Minutes, Hours, Days).

#### **2. Filters**
Rule-based logic to include/exclude products.
*   **Filter Name:** Identifier.
*   **API Source:** Select API to apply filter on.
*   **Rules Engine:**
    *   **Dynamic Rows:** Add/Remove rules.
    *   **Fields per Rule:**
        *   *WC Attribute*: (e.g., `stock_quantity`)
        *   *Operator*: `=`, `!=`, `>`, `<`, `Contains`, etc.
        *   *Supplier Attribute*: Value to compare against.
    *   **Combine Operator:** `AND` / `OR` logic between rules.

#### **3. Optimization**
*   **Batch Settings:**
    *   Enable/Disable per connection.
    *   **Batch Size:** Number of records per request.
*   **Page Settings:**
    *   Enable/Disable per connection.
    *   **Per Page:** Number of records per page.
    *   **Pagination Type:** Page Number vs Offset.

## 4. Utility / System
*   **License Management:** Activate/Deactivate plugin license.
*   **Debug Logs:** View internal application logs for troubleshooting.
*   **User Accounts:** Application-specific user management (if separate from WP Users).
