# DOJ API Documentation

Dokumentasi lengkap semua API yang aktif pada aplikasi Department of Justice (DOJ).

## Base URL

| Environment | URL |
|-------------|-----|
| Local | `http://localhost:8001/api` |
| Production | `https://doj.satumimpirp.id/api` |

---

## Authentication

### API Key (middleware `api.key`)

Endpoint yang dilindungi memerlukan API Key. Kirim melalui salah satu cara:

```
Header: X-API-Key: <your-api-key>
Query:  ?api_key=<your-api-key>
```

Prioritas: header `X-API-Key` digunakan terlebih dahulu.

**Response jika unauthorized (401):**

```json
{
  "success": false,
  "message": "Unauthorized. API key tidak valid atau tidak disertakan."
}
```

### Environment Variables

```env
# DOJ .env
DOJ_API_KEY=your-api-key
```

---

## 0. VRC Requests API

> Protected by `api.key` middleware
>
> Akses yang diberikan hanya untuk read-only: list dan detail.
> Tidak ada endpoint create, update, atau delete untuk VRC.

### 0.1 List VRC Requests

```
GET /api/vrc-requests
```

Endpoint read-only untuk membagikan data VRC ke server lain.

#### Akses Yang Disediakan

- List data VRC: `GET /api/vrc-requests`
- Detail data VRC: `GET /api/vrc-requests/{id}`

#### Query Parameters (Optional)

| Parameter | Behavior | Contoh |
|-----------|----------|--------|
| `status` | Exact match: `pending` \| `approved` \| `rejected` | `?status=approved` |
| `application_no` | Partial match | `?application_no=VRC-2026` |
| `veh_plat` | Partial match plat kendaraan | `?veh_plat=AB1234CD` |
| `owner_name` | Partial match nama pemilik | `?owner_name=andi` |
| `owner_nik` | Partial match NIK pemilik | `?owner_nik=3273` |
| `date_from` | Filter tanggal awal (`YYYY-MM-DD`) | `?date_from=2026-06-01` |
| `date_to` | Filter tanggal akhir (`YYYY-MM-DD`) | `?date_to=2026-06-30` |
| `per_page` | Jumlah data per halaman, default `15`, max `100` | `?per_page=25` |

#### Contoh Request

```bash
curl http://localhost:8001/api/vrc-requests \
  -H "X-API-Key: your-api-key"

curl "http://localhost:8001/api/vrc-requests?status=approved&per_page=10" \
  -H "X-API-Key: your-api-key"

curl "http://localhost:8001/api/vrc-requests?owner_name=andi&veh_plat=AB1234CD" \
  -H "X-API-Key: your-api-key"
```

#### Response 200

```json
{
  "success": true,
  "message": "Ditemukan 42 data VRC.",
  "data": [
    {
      "id": 1,
      "application_no": "VRC-2026-0001",
      "date": "2026-06-01",
      "status": "approved",
      "rejection_notes": null,
      "vehicle": {
        "id": 10,
        "veh_plat": "AB1234CD",
        "veh_type": "Sedan",
        "veh_color": "Black",
        "veh_img": ["https://..."],
        "status": "registered",
        "expdate": "2026-07-01 00:00:00",
        "owner": {
          "id": 5,
          "name": "Andi",
          "username": "andi123",
          "nik": "3273010101010001",
          "phone": "08123456789",
          "job": "civilian"
        }
      },
      "owner": {
        "id": 5,
        "name": "Andi",
        "username": "andi123",
        "nik": "3273010101010001",
        "phone": "08123456789",
        "job": "civilian",
        "discord_id": "1234567890"
      },
      "accepted_by": {
        "id": 2,
        "name": "Officer DOJ"
      },
      "created_at": "2026-06-01T10:00:00+00:00",
      "updated_at": "2026-06-01T10:15:00+00:00"
    }
  ],
  "pagination": {
    "current_page": 1,
    "per_page": 15,
    "total": 42,
    "last_page": 3,
    "from": 1,
    "to": 15,
    "next_page_url": "http://localhost:8001/api/vrc-requests?page=2",
    "prev_page_url": null
  }
}
```

#### Response 404

```json
{
  "success": false,
  "message": "Data tidak ditemukan.",
  "data": null
}
```

### 0.2 Show VRC Request

```
GET /api/vrc-requests/{id}
```

Parameter `{id}` bisa berupa numeric primary key atau `application_no`.

#### Contoh Request

```bash
curl http://localhost:8001/api/vrc-requests/1 \
  -H "X-API-Key: your-api-key"

curl http://localhost:8001/api/vrc-requests/VRC-2026-0001 \
  -H "X-API-Key: your-api-key"
```

#### Response 200

```json
{
  "success": true,
  "message": "success",
  "data": {
    "id": 1,
    "application_no": "VRC-2026-0001",
    "date": "2026-06-01",
    "status": "approved",
    "rejection_notes": null,
    "vehicle": {
      "id": 10,
      "veh_plat": "AB1234CD",
      "veh_type": "Sedan",
      "veh_color": "Black",
      "veh_img": ["https://..."],
      "status": "registered",
      "expdate": "2026-07-01 00:00:00",
      "owner": {
        "id": 5,
        "name": "Andi",
        "username": "andi123",
        "nik": "3273010101010001",
        "phone": "08123456789",
        "job": "civilian"
      }
    },
    "owner": {
      "id": 5,
      "name": "Andi",
      "username": "andi123",
      "nik": "3273010101010001",
      "phone": "08123456789",
      "job": "civilian",
      "discord_id": "1234567890"
    },
    "accepted_by": {
      "id": 2,
      "name": "Officer DOJ"
    },
    "created_at": "2026-06-01T10:00:00+00:00",
    "updated_at": "2026-06-01T10:15:00+00:00"
  }
}
```

#### Response 404

```json
{
  "success": false,
  "message": "Data tidak ditemukan.",
  "data": null
}
```

### Data Fields - VRC Request

| Field | Type | Keterangan |
|-------|------|------------|
| `id` | integer | Primary key |
| `application_no` | string | Nomor permohonan VRC |
| `date` | string | Tanggal pengajuan `YYYY-MM-DD` |
| `status` | string | `pending` \| `approved` \| `rejected` |
| `rejection_notes` | string/null | Catatan penolakan |
| `vehicle` | object/null | Data kendaraan yang diajukan |
| `owner` | object/null | Data pemilik/pemohon |
| `accepted_by` | object/null | Petugas DOJ yang memproses |
| `created_at` | string | ISO 8601 datetime |
| `updated_at` | string | ISO 8601 datetime |

### Pagination Metadata

| Field | Type | Keterangan |
|-------|------|------------|
| `current_page` | integer | Halaman aktif |
| `per_page` | integer | Data per halaman |
| `total` | integer | Total seluruh data |
| `last_page` | integer | Halaman terakhir |
| `from` | integer/null | Index data awal pada halaman ini |
| `to` | integer/null | Index data akhir pada halaman ini |
| `next_page_url` | string/null | URL halaman berikutnya |
| `prev_page_url` | string/null | URL halaman sebelumnya |

---

## Daftar API

| # | Endpoint | Method | Auth | Keterangan |
|---|----------|--------|------|------------|
| 1 | `/api/arrest-warrant-requests` | GET | API Key | List arrest warrant requests |
| 2 | `/api/arrest-warrant-requests/{id}` | GET | API Key | Detail arrest warrant request |
| 3 | `/api/search-warrant-requests` | GET | API Key | List search warrant requests |
| 4 | `/api/search-warrant-requests/{id}` | GET | API Key | Detail search warrant request |
| 5 | `/api/criminal-cases` | GET | API Key | List criminal cases |
| 6 | `/api/criminal-cases` | POST | API Key | Create criminal case |
| 7 | `/api/criminal-cases/{id}` | GET | API Key | Detail criminal case |
| 8 | `/api/criminal-cases/{id}/update` | POST | API Key | Update criminal case |
| 9 | `/api/charges` | GET | Publik | List semua charges |
| 10 | `/api/charges` | POST | Publik | Create charge |
| 11 | `/api/charges/{id}` | GET | Publik | Detail charge |
| 12 | `/api/charges/{id}` | PUT | Publik | Update charge |
| 13 | `/api/charges/{id}` | DELETE | Publik | Delete charge |
| 14 | `/api/vrc/search` | POST | Publik | Search VRC data |
| 15 | `/api/vrc-requests` | GET | API Key | List VRC requests |
| 16 | `/api/vrc-requests/{id}` | GET | API Key | Detail VRC request |

---

## 1. Arrest Warrant Requests API

> Protected by `api.key` middleware
>
> Akses khusus **Read-Only**: hanya menampilkan data yang berstatus **`approved`** (tidak termasuk `pending`, `rejected`, atau `completed`).

### 1.1 List Arrest Warrant Requests (Approved Only)

```
GET /api/arrest-warrant-requests
```

#### Query Parameters (Optional)

| Parameter | Behavior | Contoh |
|-----------|----------|--------|
| `suspect_name` | Partial match, case-insensitive | `?suspect_name=dudung` |
| `application_no` | Partial match | `?application_no=AW-CR-2026` |
| `cid_no` | Partial match | `?cid_no=CID-001` |

#### Contoh Request

```bash
# Semua data Arrest Warrant Approved
curl http://localhost:8001/api/arrest-warrant-requests \
  -H "X-API-Key: your-api-key"

# Filter by suspect_name
curl "http://localhost:8001/api/arrest-warrant-requests?suspect_name=dudung" \
  -H "X-API-Key: your-api-key"
```

#### Response 200

```json
{
  "success": true,
  "message": "Ditemukan 5 data.",
  "data": [
    {
      "id": 1,
      "application_no": "AW-CR-2026-0001",
      "cid_no": "CID-2026-001",
      "suspect_name": "Dudung Syahur",
      "suspect_dob": "1990-05-15",
      "photo_url": "https://r2.fivemanage.com/...",
      "link_investigation_report": "https://...",
      "remark": "Catatan tambahan",
      "status": "approved",
      "prosecutor": {
        "id": 5,
        "name": "Nash Branford"
      },
      "judge": {
        "id": 10,
        "name": "Peach Elstone"
      },
      "submitted_by": {
        "id": 3,
        "name": "Officer A"
      },
      "accepted_by": {
        "id": 7,
        "name": "Officer B"
      },
      "charges": [
        {
          "id": 1,
          "code": "PC",
          "section": "5.1",
          "name": "Obstruction of Justice"
        }
      ],
      "created_at": "2026-05-28T10:00:00+00:00",
      "updated_at": "2026-05-28T12:00:00+00:00"
    }
  ]
}
```

---

### 1.2 Show Arrest Warrant Request

```
GET /api/arrest-warrant-requests/{id}
```

Parameter `{id}` adalah numeric primary key.

#### Contoh Request

```bash
curl http://localhost:8001/api/arrest-warrant-requests/1 \
  -H "X-API-Key: your-api-key"
```

#### Response 200

```json
{
  "success": true,
  "message": "success",
  "data": {
    "id": 1,
    "application_no": "AW-CR-2026-0001",
    "cid_no": "CID-2026-001",
    "suspect_name": "Dudung Syahur",
    "suspect_dob": "1990-05-15",
    "photo_url": "https://r2.fivemanage.com/...",
    "link_investigation_report": "https://...",
    "remark": null,
    "status": "approved",
    "prosecutor": {
      "id": 5,
      "name": "Nash Branford"
    },
    "judge": {
      "id": 10,
      "name": "Peach Elstone"
    },
    "submitted_by": {
      "id": 3,
      "name": "Officer A"
    },
    "accepted_by": {
      "id": 7,
      "name": "Officer B"
    },
    "charges": [
      {
        "id": 1,
        "code": "PC",
        "section": "5.1",
        "name": "Obstruction of Justice",
        "description": "Menghalangi proses hukum...",
        "imprisonment": 30,
        "fine": 5000
      }
    ],
    "created_at": "2026-05-28T10:00:00+00:00",
    "updated_at": "2026-05-28T12:00:00+00:00"
  }
}
```

#### Response 404

```json
{
  "success": false,
  "message": "Data tidak ditemukan.",
  "data": null
}
```

---

### Data Fields - Arrest Warrant Request

| Field | Type | Keterangan |
|-------|------|------------|
| `id` | integer | Primary key |
| `application_no` | string | Nomor permohonan (format: `AW-CR-{YEAR}-{XXXX}`) |
| `cid_no` | string | CID case number |
| `suspect_name` | string | Nama tersangka |
| `suspect_dob` | string/null | Tanggal lahir tersangka |
| `photo_url` | string/null | URL foto tersangka (CDN) |
| `link_investigation_report` | string/null | Link laporan investigasi |
| `remark` | string/null | Catatan tambahan |
| `status` | string | `pending` \| `approved` \| `rejected` |
| `prosecutor` | object/null | `{id, name}` — Jaksa penuntut |
| `judge` | object/null | `{id, name}` — Hakim |
| `submitted_by` | object/null | `{id, name}` — User yang submit |
| `accepted_by` | object/null | `{id, name}` — Officer yang approve/reject |
| `charges` | array | List charges `[{id, code, section, name, ...}]` |
| `created_at` | string | ISO 8601 datetime |
| `updated_at` | string | ISO 8601 datetime |

---

## 2. Search Warrant Requests API

> Protected by `api.key` middleware
>
> Akses khusus **Read-Only**: hanya menampilkan data yang berstatus **`approved`** (tidak termasuk `pending`, `rejected`, atau `completed`).

### 2.1 List Search Warrant Requests (Approved Only)

```
GET /api/search-warrant-requests
```

#### Query Parameters (Optional)

| Parameter | Behavior | Contoh |
|-----------|----------|--------|
| `premises` | Partial match, case-insensitive | `?premises=Jalan Mawar` |
| `person` | Partial match, case-insensitive | `?person=Budi` |
| `application_no` | Partial match | `?application_no=SW-CR-2026` |
| `cid_no` | Partial match | `?cid_no=CID-002` |

#### Contoh Request

```bash
# Semua data Search Warrant Approved
curl http://localhost:8001/api/search-warrant-requests \
  -H "X-API-Key: your-api-key"

# Filter by premises
curl "http://localhost:8001/api/search-warrant-requests?premises=Jalan%20Mawar" \
  -H "X-API-Key: your-api-key"
```

#### Response 200

```json
{
  "success": true,
  "message": "Ditemukan 5 data.",
  "data": [
    {
      "id": 1,
      "application_no": "SW-CR-2026-0001",
      "cid_no": "CID-2026-002",
      "premises": "Jalan Mawar No 10",
      "person_in_occupation": "Budi Santoso",
      "link_investigation_report": "https://...",
      "status": "approved",
      "prosecutor": {
        "id": 5,
        "name": "Nash Branford"
      },
      "judge": {
        "id": 10,
        "name": "Peach Elstone"
      },
      "submitted_by": {
        "id": 3,
        "name": "Officer A"
      },
      "accepted_by": {
        "id": 7,
        "name": "Officer B"
      },
      "charges": [
        {
          "id": 1,
          "code": "PC",
          "section": "5.1",
          "name": "Obstruction of Justice"
        }
      ],
      "created_at": "2026-05-28T10:00:00+00:00",
      "updated_at": "2026-05-28T12:00:00+00:00"
    }
  ]
}
```

---

### 2.2 Show Search Warrant Request

```
GET /api/search-warrant-requests/{id}
```

Parameter `{id}` adalah numeric primary key.

#### Contoh Request

```bash
curl http://localhost:8001/api/search-warrant-requests/1 \
  -H "X-API-Key: your-api-key"
```

#### Response 200

```json
{
  "success": true,
  "message": "success",
  "data": {
    "id": 1,
    "application_no": "SW-CR-2026-0001",
    "cid_no": "CID-2026-002",
    "premises": "Jalan Mawar No 10",
    "person_in_occupation": "Budi Santoso",
    "link_investigation_report": "https://...",
    "status": "approved",
    "prosecutor": {
      "id": 5,
      "name": "Nash Branford"
    },
    "judge": {
      "id": 10,
      "name": "Peach Elstone"
    },
    "submitted_by": {
      "id": 3,
      "name": "Officer A"
    },
    "accepted_by": {
      "id": 7,
      "name": "Officer B"
    },
    "charges": [
      {
        "id": 1,
        "code": "PC",
        "section": "5.1",
        "name": "Obstruction of Justice",
        "description": "Menghalangi proses hukum...",
        "imprisonment": 30,
        "fine": 5000
      }
    ],
    "created_at": "2026-05-28T10:00:00+00:00",
    "updated_at": "2026-05-28T12:00:00+00:00"
  }
}
```

#### Response 404

```json
{
  "success": false,
  "message": "Data tidak ditemukan.",
  "data": null
}
```

---

### Data Fields - Search Warrant Request

| Field | Type | Keterangan |
|-------|------|------------|
| `id` | integer | Primary key |
| `application_no` | string | Nomor permohonan |
| `cid_no` | string | CID case number |
| `premises` | string | Lokasi/tempat penggeledahan |
| `person_in_occupation` | string | Penghuni/pemilik tempat |
| `link_investigation_report` | string/null | Link laporan investigasi |
| `status` | string | `pending` \| `approved` \| `rejected` |
| `prosecutor` | object/null | `{id, name}` — Jaksa penuntut |
| `judge` | object/null | `{id, name}` — Hakim |
| `submitted_by` | object/null | `{id, name}` — User yang submit |
| `accepted_by` | object/null | `{id, name}` — Officer yang approve/reject |
| `charges` | array | List charges `[{id, code, section, name, ...}]` |
| `created_at` | string | ISO 8601 datetime |
| `updated_at` | string | ISO 8601 datetime |

---

## 3. Criminal Cases API

> Protected by `api.key` middleware
> Dokumentasi lengkap: lihat `CRIMINAL_CASES_API.md`

### Endpoints

| Method | Endpoint | Keterangan |
|--------|----------|------------|
| GET | `/api/criminal-cases` | List dengan filter (cid_no, accused_name, status) |
| POST | `/api/criminal-cases` | Create criminal case baru |
| GET | `/api/criminal-cases/{id}` | Detail by ID atau CID number |
| POST | `/api/criminal-cases/{id}/update` | Update criminal case |

### Status Values

`active` | `closed` | `arraignment` | `trial` | `sentence` | `search warrant` | `arrest warrant` | `withdrawn`

---

## 3. Charges API

> Publik (tanpa auth)

### 3.1 List All Charges

```
GET /api/charges
```

```bash
curl http://localhost:8001/api/charges
```

**Response 200:**

```json
{
  "success": true,
  "data": [
    {
      "id": 1,
      "code": "PC",
      "section": "1.1",
      "name": "First Degree Murder",
      "description": "...",
      "imprisonment": 999,
      "fine": 0,
      "notes": null,
      "created_at": "...",
      "updated_at": "..."
    }
  ]
}
```

### 3.2 Show Charge

```
GET /api/charges/{id}
```

### 3.3 Create Charge

```
POST /api/charges
```

| Field | Type | Required | Validasi |
|-------|------|----------|----------|
| `code` | string | ✅ | Max 50 |
| `section` | string | ✅ | Max 100, unique |
| `name` | string | ✅ | Max 255 |
| `description` | string | ✅ | - |
| `imprisonment` | integer | ❌ | Nullable |
| `fine` | integer | ❌ | Nullable |
| `notes` | string | ❌ | Nullable |

### 3.4 Update Charge

```
PUT /api/charges/{id}
```

Semua field bersifat `sometimes` (partial update).

### 3.5 Delete Charge

```
DELETE /api/charges/{id}
```

---

## 4. VRC Search API

> Publik (tanpa auth)

### Search VRC

```
POST /api/vrc/search
```

Mencari data Vehicle Registration Certificate berdasarkan keyword.

#### Request Body

| Field | Type | Required | Keterangan |
|-------|------|----------|------------|
| `data` | string | ✅ | Keyword pencarian (nama, NIK, plat, atau nomor VRC) |

#### Contoh Request

```bash
curl -X POST http://localhost:8001/api/vrc/search \
  -H "Content-Type: application/json" \
  -d '{"data": "B 1234 XYZ"}'
```

#### Response 200

```json
{
  "success": true,
  "message": "Ditemukan 1 data.",
  "data": [
    {
      "veh_plat": "B 1234 XYZ",
      "veh_color": "Black",
      "veh_img": ["https://..."],
      "owner_name": "John Doe",
      "owner_nik": "1234567890",
      "vrc_number": "VRC-2026-0001",
      "vrc_status": "approved",
      "expdate": "2027-05-28 00:00:00",
      "accept": {
        "id": 5,
        "name": "Officer A"
      },
      "vehicle_status": "registered"
    }
  ]
}
```

#### Response 404

```json
{
  "success": false,
  "message": "Data tidak ditemukan.",
  "data": []
}
```

#### Vehicle Status Values

| Status | Keterangan |
|--------|------------|
| `registered` | Kendaraan terdaftar dan aktif |
| `not registered` | Tidak terdaftar atau expired |
| `suspend` | Ditangguhkan |

---

## Error Responses (Global)

| HTTP Status | Kondisi | Response |
|-------------|---------|----------|
| 200 | Success (GET/PUT) | `{"success": true, ...}` |
| 201 | Created (POST) | `{"success": true, ...}` |
| 401 | Unauthorized (API Key) | `{"success": false, "message": "Unauthorized..."}` |
| 404 | Not Found | `{"success": false, "message": "Data tidak ditemukan."}` |
| 422 | Validation Error | `{"success": false, "message": "...", "errors": {...}}` |

---

## Integrasi dengan Aplikasi Lain

### Environment Variables (Aplikasi Client)

```env
DOJ_API_URL=https://doj.satumimpirp.id/api
DOJ_API_KEY=your-api-key
```

### Contoh Service (Laravel)

```php
use Illuminate\Support\Facades\Http;

class DojApiService
{
    public function getArrestWarrants(array $filters = [])
    {
        return Http::withHeaders([
            'X-API-Key' => config('services.doj.api_key'),
        ])->get(config('services.doj.url') . '/arrest-warrant-requests', $filters)
          ->json();
    }

    public function getArrestWarrant(int $id)
    {
        return Http::withHeaders([
            'X-API-Key' => config('services.doj.api_key'),
        ])->get(config('services.doj.url') . '/arrest-warrant-requests/' . $id)
          ->json();
    }
}
```

### Config (services.php)

```php
'doj' => [
    'url' => env('DOJ_API_URL', 'https://doj.satumimpirp.id/api'),
    'api_key' => env('DOJ_API_KEY'),
],
```
