# Product Master API Requirements (For FE Table UI)

Dokumen ini untuk sinkronisasi BE dengan UI FE terbaru pada menu:

- Sidebar `Product` -> sub menu `Product`

UI yang dipakai sekarang adalah model datatable seperti referensi:

- list item product (pagination + search)
- tombol add/edit/delete
- import excel
- export excel

## Endpoint yang Dibutuhkan

## 1) List Product (datatable)

`GET /api/v1/products`

Query params:

- `page` (int, default `1`)
- `limit` (int, default `10`)
- `search` (string, optional)
- `sort_by` (string, optional, contoh: `name`, `item_code`, `created_at`)
- `sort_order` (`asc|desc`, optional)

Response contoh:

```json
{
  "items": [
    {
      "id": 1,
      "item_code": "VLRMC020006",
      "barcode": "91031102000601",
      "name": "ABSTRACT TROPICAL",
      "brand": "RYCROFT",
      "category": "VOLLEY SHORT",
      "size": "S",
      "collection": "2024 Q4",
      "is_consignment": true
    }
  ],
  "meta": {
    "page": 1,
    "limit": 10,
    "total_items": 454,
    "total_pages": 46
  }
}
```

## 2) Create Product

`POST /api/v1/products`

Payload minimal:

```json
{
  "item_code": "VLRMC020006",
  "barcode": "91031102000601",
  "name": "ABSTRACT TROPICAL",
  "brand": "RYCROFT",
  "category": "VOLLEY SHORT",
  "size": "S",
  "collection": "2024 Q4",
  "base_price": 1099000,
  "is_consignment": true
}
```

## 3) Update Product

`PUT /api/v1/products/:id`

## 4) Delete Product (opsi hard/soft delete)

`DELETE /api/v1/products/:id`

Disarankan soft delete:

- set `is_active=false`

## 5) Import Product Excel

`POST /api/v1/import/products`

- multipart/form-data
- field file: `file`
- field optional: `dry_run` (`true|false`)

Response:

```json
{
  "job_id": 123,
  "status": "processing"
}
```

## 6) Export Product Excel

`GET /api/v1/export/products`

- return file `application/vnd.openxmlformats-officedocument.spreadsheetml.sheet`

## 7) Import Job Detail

`GET /api/v1/import/jobs/:id`

Response contoh:

```json
{
  "id": 123,
  "file_name": "master-product.xlsx",
  "status": "success",
  "total_rows": 1522,
  "success_rows": 1520,
  "failed_rows": 2,
  "errors": [
    { "row": 15, "message": "ITEM CODE duplicate" }
  ]
}
```

## Perubahan Schema yang Disarankan

Pada tabel `bazzar_pos.products`, tambahkan field:

- `is_consignment BOOLEAN NOT NULL DEFAULT FALSE`

Contoh migration:

```sql
ALTER TABLE bazzar_pos.products
ADD COLUMN IF NOT EXISTS is_consignment BOOLEAN NOT NULL DEFAULT FALSE;
```

## Role Permission

- `superadmin`: full CRUD + import/export + approve pricing
- `admin`: CRUD + import/export (approval pricing tetap via superadmin)
- `cashier`: read-only list untuk POS (tanpa edit/delete/import)

## Catatan Integrasi FE

FE screen sudah aktif:

- menu `Product` -> sub `Product` (datatable UI)

Masih memakai data mock untuk tampilan. Setelah endpoint siap, FE tinggal binding ke API modules.

