# 📚 Complete API Documentation - Saladdin LMS

**Base URL:** `http://localhost:8000/api`

Dokumentasi lengkap untuk SEMUA endpoint yang tersedia di sistem LMS Saladdin.

---

## 📑 Table of Contents

1. [Authentication](#authentication)
2. [Public Endpoints](#public-endpoints)
3. [Student/User Endpoints](#student-endpoints)
4. [Admin - Course Management](#admin-course)
5. [Admin - Content Management](#admin-content)
6. [Admin - Certificate Management](#admin-certificate)

---

## 🔐 Authentication {#authentication}

### 1. Register (Daftar Akun)

```http
POST /api/auth/register
Content-Type: application/json
```

**Request Body:**

```json
{
    "name": "Ahmad Saladdin",
    "email": "saladdin@example.com",
    "password": "password123",
    "password_confirmation": "password123"
}
```

**Response 201:**

```json
{
    "message": "Registration successful",
    "access_token": "1|xyz...",
    "token_type": "Bearer",
    "user": {
        "id": 1,
        "name": "Ahmad Saladdin",
        "email": "saladdin@example.com",
        "role": "student",
        "created_at": "2026-01-27T10:30:00.000000Z"
    }
}
```

---

### 2. Login

```http
POST /api/auth/login
Content-Type: application/json
```

**Request Body:**

```json
{
    "email": "saladdin@example.com",
    "password": "password123"
}
```

**Response 200:**

```json
{
    "message": "Login successful",
    "access_token": "2|abc...",
    "token_type": "Bearer",
    "user": {
        "id": 1,
        "name": "Ahmad Saladdin",
        "email": "saladdin@example.com",
        "role": "student"
    }
}
```

**Error 401:**

```json
{
    "message": "Invalid login credentials"
}
```

---

### 3. Logout

```http
POST /api/auth/logout
Authorization: Bearer {token}
```

**Response 200:**

```json
{
    "message": "Logged out successfully"
}
```

---

### 4. Get Current User

```http
GET /api/auth/me
Authorization: Bearer {token}
```

**Response 200:**

```json
{
    "id": 1,
    "name": "Ahmad Saladdin",
    "email": "saladdin@example.com",
    "role": "student",
    "avatar": null,
    "created_at": "2026-01-27T10:30:00.000000Z"
}
```

---

### 5. Google OAuth - Redirect

```http
GET /api/auth/google
```

**Response:** Redirect ke Google Login

---

### 6. Google OAuth - Callback

```http
GET /api/auth/google/callback
```

**Response:** Redirect ke Frontend dengan token di URL:

```
http://localhost:3000/auth/callback?token={token}&user={json}
```

---

## 🌐 Public Endpoints {#public-endpoints}

### 7. Get Single Course (Public Detail)

```http
GET /api/courses/{slug}
```

**Response 200:**

```json
{
    "status": "success",
    "data": {
        "id": 1,
        "title": "Laravel Advanced",
        "slug": "laravel-advanced-xyz",
        "description": "Complete Laravel course...",
        "instructor": "Dr. Ahmad Marifi",
        "price": 149000,
        "price_formatted": "Rp 149.000",
        "thumbnail": "http://localhost:8000/storage/thumbnails/xyz.jpg",
        "is_enrolled": true,
        "progress": 65.5,
        "sections": [
            {
                "id": 1,
                "title": "Introduction",
                "lessons": [
                    {
                        "id": 1,
                        "title": "Welcome Video",
                        "slug": "welcome-video",
                        "type": "video",
                        "is_completed": true
                    },
                    {
                        "id": 2,
                        "title": "Course Overview",
                        "slug": "course-overview",
                        "type": "text",
                        "is_completed": false
                    }
                ]
            }
        ]
    }
}
```

**Notes:**

- `is_completed`: `true` jika user sudah menyelesaikan lesson tersebut, `false` jika belum
- Jika user belum login atau belum enroll, semua `is_completed` akan `false`
- `progress`: persentase keseluruhan progress kursus (null jika belum enroll)

````

---

### 8. Verify Certificate (Public)

```http
GET /api/certificates/verify/{certificateNumber}
````

**Example:** `/api/certificates/verify/CERT-2026-001234`

**Response 200:**

```json
{
    "valid": true,
    "certificate_number": "CERT-2026-001234",
    "student_name": "Ahmad Saladdin",
    "course_title": "Laravel Advanced",
    "instructor": "Dr. Ahmad Marifi",
    "issued_at": "27 January 2026",
    "completion_date": "25 January 2026"
}
```

**Error 404:**

```json
{
    "valid": false,
    "message": "Certificate not found or invalid."
}
```

---

## 👨‍🎓 Student/User Endpoints {#student-endpoints}

> **Note:** Semua endpoint memerlukan `Authorization: Bearer {token}`

### 9. Get All Courses (Catalog)

```http
GET /api/courses?q={search}
Authorization: Bearer {token}
```

**Query Parameters:**

- `q`: Search by title (optional)

**Response 200:**

```json
{
    "status": "success",
    "data": [
        {
            "id": 1,
            "title": "Laravel Advanced",
            "slug": "laravel-advanced-xyz",
            "instructor_name": "Dr. Ahmad Marifi",
            "price": 149000,
            "thumbnail": "http://localhost:8000/storage/thumbnails/xyz.jpg",
            "is_enrolled": true
        }
    ]
}
```

---

### 10. Enroll Course (Gratis)

```http
POST /api/courses/{courseId}/enroll
Authorization: Bearer {token}
```

**Response 200:**

```json
{
    "status": "success",
    "message": "Enrollment successful! You can now access the course."
}
```

**Error 400 (Already Enrolled):**

```json
{
    "status": "error",
    "message": "You are already enrolled in this course."
}
```

**Error 400 (Admin):**

```json
{
    "status": "error",
    "message": "Admin memiliki akses penuh tanpa perlu enrollment."
}
```

---

### 11. Get My Courses

```http
GET /api/my-courses
Authorization: Bearer {token}
```

**Response 200:**

```json
{
    "status": "success",
    "data": [
        {
            "id": 1,
            "title": "Laravel Advanced",
            "slug": "laravel-advanced-xyz",
            "progress_percentage": 65.5,
            "last_accessed": "2026-01-27T08:30:00.000000Z"
        }
    ]
}
```

---

### 12. Get Lesson Detail

```http
GET /api/lessons/{lessonId}
Authorization: Bearer {token}
```

**Response 200 (Video):**

```json
{
    "status": "success",
    "data": {
        "id": 1,
        "title": "Welcome Video",
        "slug": "welcome-video",
        "type": "video",
        "content_source": "external",
        "content_url": "https://youtube.com/watch?v=xxx",
        "is_completed": false,
        "section": {
            "id": 1,
            "title": "Introduction"
        }
    }
}
```

**Response 200 (Quiz):**

```json
{
    "status": "success",
    "data": {
        "id": 5,
        "title": "Module 1 Quiz",
        "type": "quiz",
        "total_questions": 10,
        "passing_score": 70,
        "attempts_left": 3
    }
}
```

---

### 13. Get Quiz Question (1-by-1)

```http
GET /api/lessons/{lessonId}/questions/{seq}
Authorization: Bearer {token}
```

**Example:** `/api/lessons/5/questions/1`

**Response 200:**

```json
{
    "status": "success",
    "data": {
        "id": 1,
        "question_text": "What is Laravel?",
        "points": 10,
        "options": [
            {
                "id": 1,
                "option_text": "PHP Framework"
            },
            {
                "id": 2,
                "option_text": "JavaScript Library"
            },
            {
                "id": 3,
                "option_text": "Database System"
            }
        ]
    },
    "total_questions": 10,
    "current_seq": 1
}
```

---

### 14. Submit Quiz Answers

```http
POST /api/lessons/{lessonId}/submit-quiz
Authorization: Bearer {token}
Content-Type: application/json
```

**Request Body:**

```json
{
    "answers": {
        "1": 1,
        "2": 5,
        "3": 9
    }
}
```

> Key = sequence number, Value = option_id

**Response 200:**

```json
{
    "status": "success",
    "data": {
        "quiz_attempt_id": 42,
        "total_questions": 10,
        "correct_answers": 8,
        "score": 80,
        "passed": true,
        "message": "Congratulations! You passed the quiz."
    }
}
```

---

### 15. Complete Lesson (Video/Text/Document)

```http
POST /api/lessons/{lessonId}/complete
Authorization: Bearer {token}
```

**Response 200:**

```json
{
    "status": "success",
    "message": "Lesson marked as completed!"
}
```

---

### 16. Review Quiz Attempt

```http
GET /api/quiz-attempts/{attemptId}/review
Authorization: Bearer {token}
```

**Response 200:**

```json
{
    "status": "success",
    "data": {
        "attempt_id": 42,
        "lesson_title": "Module 1 Quiz",
        "score": 80,
        "passed": true,
        "submitted_at": "2026-01-27T10:30:00.000000Z",
        "questions": [
            {
                "sequence": 1,
                "question_text": "What is Laravel?",
                "points": 10,
                "your_answer": "PHP Framework",
                "correct_answer": "PHP Framework",
                "is_correct": true,
                "points_earned": 10
            },
            {
                "sequence": 2,
                "question_text": "What is Vue?",
                "points": 10,
                "your_answer": "PHP Library",
                "correct_answer": "JavaScript Framework",
                "is_correct": false,
                "points_earned": 0
            }
        ]
    }
}
```

---

### 17. Dashboard Stats

```http
GET /api/dashboard/stats
Authorization: Bearer {token}
```

**Response 200:**

```json
{
    "status": "success",
    "data": {
        "total_courses_enrolled": 5,
        "completed_courses": 2,
        "in_progress_courses": 3,
        "total_certificates": 2,
        "total_learning_hours": 48.5
    }
}
```

---

### 18. Dashboard Continue Learning

```http
GET /api/dashboard/continue-learning
Authorization: Bearer {token}
```

**Response 200:**

```json
{
    "status": "success",
    "data": {
        "lesson_id": 15,
        "lesson_title": "Advanced Routing",
        "course_id": 1,
        "course_title": "Laravel Advanced",
        "course_slug": "laravel-advanced-xyz",
        "section_title": "Chapter 3",
        "progress_percentage": 65.5,
        "last_accessed": "2026-01-27T08:30:00.000000Z"
    }
}
```

**Response 200 (No lessons yet):**

```json
{
    "status": "success",
    "data": null,
    "message": "Belum ada lesson yang diselesaikan."
}
```

---

### 19. Get My Certificates

```http
GET /api/my-certificates
Authorization: Bearer {token}
```

**Response 200:**

```json
{
    "certificates": [
        {
            "id": 1,
            "certificate_number": "CERT-2026-001234",
            "course_title": "Laravel Advanced",
            "course_slug": "laravel-advanced-xyz",
            "instructor": "Dr. Ahmad Marifi",
            "issued_at": "27 January 2026",
            "verification_url": "http://localhost:8000/api/certificates/verify/CERT-2026-001234"
        }
    ]
}
```

---

### 20. Get Certificate Detail

```http
GET /api/certificates/{id}
Authorization: Bearer {token}
```

**Response 200:**

```json
{
    "id": 1,
    "certificate_number": "CERT-2026-001234",
    "student_name": "Ahmad Saladdin",
    "course": {
        "id": 1,
        "title": "Laravel Advanced",
        "instructor": "Dr. Ahmad Marifi"
    },
    "issued_at": "27 January 2026",
    "config": {
        "template_type": "classic",
        "primary_color": "#1e3a8a",
        "secondary_color": "#d4af37"
    },
    "signatures": [
        {
            "name": "Dr. Ahmad Marifi",
            "title": "Instructor",
            "signature_url": "http://localhost:8000/storage/signatures/xyz.png",
            "order": 1
        }
    ]
}
```

---

### 21. Download Certificate PDF

```http
GET /api/certificates/{id}/download
Authorization: Bearer {token}
```

**Response 200:** Binary PDF file download

**Headers:**

```
Content-Type: application/pdf
Content-Disposition: attachment; filename="CERT-2026-001234.pdf"
```

---

## 👨‍💼 Admin - Course Management {#admin-course}

> **Note:** Semua endpoint memerlukan:
>
> - `Authorization: Bearer {admin_token}`
> - Role: `admin`

### 22. Admin - List All Courses

```http
GET /api/admin/courses?status={status}&search={keyword}&instructor={name}&per_page=15
Authorization: Bearer {admin_token}
```

**Query Parameters:**

- `status`: draft | published (optional)
- `search`: Search by title or description (optional)
- `instructor`: Filter by instructor name (optional)
- `per_page`: Items per page, default 15 (optional)

**Response 200:**

```json
{
    "status": "success",
    "data": {
        "current_page": 1,
        "data": [
            {
                "id": 1,
                "title": "Laravel Advanced",
                "slug": "laravel-advanced-abc123",
                "instructor_name": "Dr. Ahmad Marifi",
                "price": 149000,
                "status": "published",
                "thumbnail": "http://localhost:8000/storage/thumbnails/xyz.jpg",
                "students_count": 324,
                "sections_count": 5,
                "created_at": "2026-01-15T10:30:00.000000Z"
            }
        ],
        "per_page": 15,
        "total": 25,
        "last_page": 2
    }
}
```

---

### 23. Admin - Get Course Detail

```http
GET /api/admin/courses/{id}
Authorization: Bearer {admin_token}
```

**Response 200:**

```json
{
    "status": "success",
    "data": {
        "id": 1,
        "title": "Laravel Advanced",
        "slug": "laravel-advanced-abc123",
        "description": "Complete Laravel course...",
        "instructor_name": "Dr. Ahmad Marifi",
        "price": 149000,
        "status": "published",
        "thumbnail": "http://localhost:8000/storage/thumbnails/xyz.jpg",
        "students_count": 324,
        "sections": [
            {
                "id": 1,
                "title": "Introduction",
                "sort_order": 1,
                "lessons": [
                    {
                        "id": 1,
                        "title": "Welcome Video",
                        "type": "video",
                        "sort_order": 1
                    }
                ]
            }
        ],
        "certificate_config": {
            "template_type": "classic",
            "primary_color": "#1e3a8a"
        },
        "certificate_signatures": [
            {
                "id": 1,
                "signatory_name": "Dr. Ahmad Marifi",
                "signatory_title": "Instructor",
                "order": 1
            }
        ]
    }
}
```

---

### 24. Admin - Create Course

```http
POST /api/admin/courses
Authorization: Bearer {admin_token}
Content-Type: multipart/form-data
```

**Body (form-data):**

```
title: Laravel Advanced (required, max 255)
price: 149000 (required, numeric, min 0)
instructor_name: Dr. Ahmad Marifi (required)
description: Complete course description (optional)
thumbnail: [File] max 2MB (optional)
```

**Response 201:**

```json
{
    "status": "success",
    "message": "Course created successfully",
    "data": {
        "id": 1,
        "title": "Laravel Advanced",
        "slug": "laravel-advanced-xyz789",
        "price": 149000,
        "status": "draft",
        "thumbnail": "http://localhost:8000/storage/thumbnails/xyz.jpg"
    }
}
```

---

### 25. Admin - Update Course

```http
PUT /api/admin/courses/{id}
Authorization: Bearer {admin_token}
Content-Type: multipart/form-data
```

**Body (form-data) - Semua optional:**

```
title: Updated Title
status: draft | published
price: 199000
instructor_name: Updated Name
description: Updated description
thumbnail: [File] New thumbnail
```

**Response 200:**

```json
{
    "status": "success",
    "message": "Course updated successfully",
    "data": {
        "id": 1,
        "title": "Updated Title",
        "status": "published"
    }
}
```

---

### 26. Admin - Delete Course

```http
DELETE /api/admin/courses/{id}
Authorization: Bearer {admin_token}
```

**Response 200:**

```json
{
    "status": "success",
    "message": "Course deleted successfully"
}
```

---

## 📖 Admin - Content Management {#admin-content}

### SECTION CRUD

### 27. Admin - List Sections in Course

```http
GET /api/admin/courses/{courseId}/sections
Authorization: Bearer {admin_token}
```

**Response 200:**

```json
{
    "status": "success",
    "data": [
        {
            "id": 1,
            "course_id": 1,
            "title": "Introduction",
            "sort_order": 1,
            "lessons_count": 3
        },
        {
            "id": 2,
            "title": "Chapter 1: Basics",
            "sort_order": 2,
            "lessons_count": 5
        }
    ]
}
```

---

### 28. Admin - Get Section Detail

```http
GET /api/admin/sections/{sectionId}
Authorization: Bearer {admin_token}
```

**Response 200:**

```json
{
    "status": "success",
    "data": {
        "id": 1,
        "course_id": 1,
        "title": "Introduction",
        "sort_order": 1,
        "lessons": [
            {
                "id": 1,
                "title": "Welcome Video",
                "type": "video",
                "sort_order": 1
            },
            {
                "id": 2,
                "title": "Module Quiz",
                "type": "quiz",
                "sort_order": 2
            }
        ]
    }
}
```

---

### 29. Admin - Create Section

```http
POST /api/admin/courses/{courseId}/sections
Authorization: Bearer {admin_token}
Content-Type: application/json
```

**Body:**

```json
{
    "title": "Introduction"
}
```

**Response 200:**

```json
{
    "status": "success",
    "data": {
        "id": 1,
        "course_id": 1,
        "title": "Introduction",
        "sort_order": 1
    }
}
```

---

### 30. Admin - Update Section

```http
PUT /api/admin/sections/{sectionId}
Authorization: Bearer {admin_token}
Content-Type: application/json
```

**Body:**

```json
{
    "title": "Updated Title",
    "order": 2
}
```

**Response 200:**

```json
{
    "status": "success",
    "data": {
        "id": 1,
        "title": "Updated Title",
        "sort_order": 2
    }
}
```

---

### 31. Admin - Delete Section

```http
DELETE /api/admin/sections/{sectionId}
Authorization: Bearer {admin_token}
```

**⚠️ Warning:** Will cascade delete all lessons in this section!

**Response 200:**

```json
{
    "status": "success",
    "message": "Section deleted successfully"
}
```

---

### LESSON CRUD

### 32. Admin - List Lessons in Section

```http
GET /api/admin/sections/{sectionId}/lessons
Authorization: Bearer {admin_token}
```

**Response 200:**

```json
{
    "status": "success",
    "data": [
        {
            "id": 1,
            "section_id": 1,
            "title": "Welcome Video",
            "type": "video",
            "sort_order": 1,
            "questions_count": 0
        },
        {
            "id": 2,
            "title": "Module 1 Quiz",
            "type": "quiz",
            "sort_order": 2,
            "questions_count": 10
        }
    ]
}
```

---

### 33. Admin - Get Lesson Detail

```http
GET /api/admin/lessons/{lessonId}
Authorization: Bearer {admin_token}
```

**Response 200:**

```json
{
    "status": "success",
    "data": {
        "id": 1,
        "section_id": 1,
        "title": "Welcome Video",
        "slug": "welcome-video-xyz",
        "type": "video",
        "content_source": "external",
        "content_url": "https://youtube.com/watch?v=xxx",
        "content_path": null,
        "content_text": null,
        "sort_order": 1,
        "section": {
            "id": 1,
            "title": "Introduction"
        },
        "questions": []
    }
}
```

---

### 34. Admin - Create Lesson

```http
POST /api/admin/sections/{sectionId}/lessons
Authorization: Bearer {admin_token}
Content-Type: multipart/form-data
```

**Body (form-data) - Video Upload:**

```
title: Welcome Video (required)
type: video (required: video|document|text|quiz)
content_source: upload (required for video/document)
content_file: [File] video.mp4 max 500MB
```

**Body - Video External (YouTube):**

```
title: Welcome Video
type: video
content_source: external
content_url: https://youtube.com/watch?v=xxx (required, must be YouTube)
```

**Body - Document:**

```
title: Course Syllabus
type: document
content_source: upload | external
content_file: [File] document.pdf OR content_url: https://...
```

**Body - Text:**

```
title: Introduction Text
type: text
content_text: Full article content here... (required)
```

**Body - Quiz:**

```
title: Module 1 Quiz
type: quiz
(No content needed, add questions via Quiz Builder)
```

**Response 201:**

```json
{
    "status": "success",
    "data": {
        "id": 1,
        "section_id": 1,
        "title": "Welcome Video",
        "type": "video",
        "slug": "welcome-video-abc123"
    }
}
```

---

### 35. Admin - Update Lesson

```http
PUT /api/admin/lessons/{lessonId}
Authorization: Bearer {admin_token}
Content-Type: multipart/form-data
```

**Body (form-data) - Semua optional:**

```
title: Updated Title
content_text: Updated text content
content_url: https://new-url.com
content_file: [File] New file (will replace old file)
```

**Response 200:**

```json
{
    "status": "success",
    "data": {
        "id": 1,
        "title": "Updated Title"
    }
}
```

---

### 36. Admin - Delete Lesson

```http
DELETE /api/admin/lessons/{lessonId}
Authorization: Bearer {admin_token}
```

**⚠️ Warning:** If quiz, will delete all questions!

**Response 200:**

```json
{
    "status": "success",
    "message": "Lesson deleted successfully"
}
```

---

### QUIZ BUILDER (Save Questions 1-1)

### 37. Admin - Get Quiz with All Questions

```http
GET /api/admin/lessons/{lessonId}/quiz
Authorization: Bearer {admin_token}
```

**Response 200:**

```json
{
    "status": "success",
    "data": {
        "id": 5,
        "title": "Module 1 Quiz",
        "type": "quiz",
        "questions": [
            {
                "id": 1,
                "lesson_id": 5,
                "question_text": "What is Laravel?",
                "points": 10,
                "sequence": 1,
                "options": [
                    {
                        "id": 1,
                        "question_id": 1,
                        "option_text": "PHP Framework",
                        "is_correct": true
                    },
                    {
                        "id": 2,
                        "option_text": "JavaScript Library",
                        "is_correct": false
                    },
                    {
                        "id": 3,
                        "option_text": "Database System",
                        "is_correct": false
                    }
                ]
            }
        ]
    }
}
```

---

### 38. Admin - Add Question (Save 1-by-1)

```http
POST /api/admin/lessons/{lessonId}/questions
Authorization: Bearer {admin_token}
Content-Type: application/json
```

**Body:**

```json
{
    "question_text": "What is Laravel?",
    "points": 10,
    "sequence": 1,
    "options": [
        {
            "option_text": "PHP Framework",
            "is_correct": true
        },
        {
            "option_text": "JavaScript Library",
            "is_correct": false
        },
        {
            "option_text": "Database System",
            "is_correct": false
        }
    ]
}
```

**Response 201:**

```json
{
    "status": "success",
    "message": "Question added successfully",
    "data": {
        "id": 1,
        "question_text": "What is Laravel?",
        "points": 10,
        "sequence": 1,
        "options": [
            {
                "id": 1,
                "option_text": "PHP Framework",
                "is_correct": true
            }
        ]
    }
}
```

---

### 39. Admin - Update Question

```http
PUT /api/admin/questions/{questionId}
Authorization: Bearer {admin_token}
Content-Type: application/json
```

**Body:**

```json
{
    "question_text": "Updated question text",
    "points": 15,
    "options": [
        {
            "option_text": "New Option 1",
            "is_correct": true
        },
        {
            "option_text": "New Option 2",
            "is_correct": false
        }
    ]
}
```

**Response 200:**

```json
{
    "status": "success",
    "data": {
        "id": 1,
        "question_text": "Updated question text",
        "points": 15
    }
}
```

---

### 40. Admin - Delete Question

```http
DELETE /api/admin/questions/{questionId}
Authorization: Bearer {admin_token}
```

**Response 200:**

```json
{
    "status": "success",
    "message": "Question deleted successfully"
}
```

---

### 41. Admin - Reorder Questions (Drag & Drop)

```http
POST /api/admin/lessons/{lessonId}/questions/reorder
Authorization: Bearer {admin_token}
Content-Type: application/json
```

**Body:**

```json
{
    "questions": [
        { "id": 3, "sequence": 1 },
        { "id": 1, "sequence": 2 },
        { "id": 2, "sequence": 3 }
    ]
}
```

**Response 200:**

```json
{
    "status": "success",
    "message": "Questions reordered successfully"
}
```

---

## 🎓 Admin - Certificate Management {#admin-certificate}

### 42. Public - Preview Certificate (Demo/Testing)

```http
GET /api/certificate-preview/{courseId}
```

**Description:** Endpoint untuk melihat preview sertifikat tanpa perlu login. Berguna untuk testing dan demo template sertifikat. Menggunakan data dummy jika belum ada data real.

**Response:** PDF file (inline display di browser)

**Contoh Akses:**

- Browser: `http://localhost:8000/api/certificate-preview/1`

**Template Features:**

- Header: Bismillahirrahmanirrahim
- Judul Sertifikat (dinamis dari config)
- Nomor Sertifikat unik
- Nama Student & Nama Kursus
- Tanggal penerbitan (format Indonesia)
- 2 Tanda Tangan (dinamis)
- QR Code untuk verifikasi (scan menuju endpoint verify)

---

### 43. Admin - Get Certificate Config

```http
GET /api/admin/courses/{courseId}/certificate
Authorization: Bearer {admin_token}
```

**Response 200:**

```json
{
    "config": {
        "id": 1,
        "template_type": "classic",
        "logo": "logos/xyz.png",
        "logo_url": "http://localhost:8000/storage/logos/xyz.png",
        "background_image": null,
        "background_url": null,
        "primary_color": "#1e3a8a",
        "secondary_color": "#d4af37",
        "certificate_text": "has successfully completed",
        "certificate_title": "SERTIFIKAT",
        "show_qr_code": true
    },
    "signatures": [
        {
            "id": 1,
            "signatory_name": "Dr. Ahmad Marifi",
            "signatory_title": "Instructor",
            "signature_image": "signatures/abc.png",
            "signature_url": "http://localhost:8000/storage/signatures/abc.png",
            "order": 1
        }
    ]
}
```

---

### 43. Admin - Create/Update Certificate Config

```http
POST /api/admin/courses/{courseId}/certificate-config
Authorization: Bearer {admin_token}
Content-Type: multipart/form-data
```

**Body (form-data):**

```
template_type: classic | modern | elegant (default: classic)
primary_color: #1e3a8a (default: #1e3a8a)
secondary_color: #d4af37 (default: #d4af37)
certificate_text: has successfully completed (optional)
certificate_title: SERTIFIKAT (default: SERTIFIKAT)
show_qr_code: true (default: true)
logo: [File] max 2MB (optional)
background_image: [File] max 5MB (optional)
```

**Response 200:**

```json
{
    "message": "Certificate configuration saved successfully.",
    "config": {
        "id": 1,
        "template_type": "classic",
        "primary_color": "#1e3a8a",
        "logo_url": "http://localhost:8000/storage/logos/xyz.png"
    }
}
```

---

### 44. Admin - Update Certificate Config

```http
PUT /api/admin/courses/{courseId}/certificate-config
Authorization: Bearer {admin_token}
Content-Type: multipart/form-data
```

**Body (form-data) - Same as Create, all optional**

**Response 200:**

```json
{
  "message": "Certificate configuration updated successfully.",
  "config": {...}
}
```

---

### 45. Admin - Delete Certificate Config

```http
DELETE /api/admin/courses/{courseId}/certificate-config
Authorization: Bearer {admin_token}
```

**Response 200:**

```json
{
    "message": "Certificate configuration deleted successfully."
}
```

---

### CERTIFICATE SIGNATURES

### 46. Admin - List Signatures

```http
GET /api/admin/courses/{courseId}/signatures
Authorization: Bearer {admin_token}
```

**Response 200:**

```json
{
    "signatures": [
        {
            "id": 1,
            "signatory_name": "Dr. Ahmad Marifi",
            "signatory_title": "Instructor",
            "signature_image": "signatures/abc.png",
            "signature_url": "http://localhost:8000/storage/signatures/abc.png",
            "order": 1
        }
    ]
}
```

---

### 47. Admin - Create Signature

```http
POST /api/admin/courses/{courseId}/signatures
Authorization: Bearer {admin_token}
Content-Type: multipart/form-data
```

**Body (form-data):**

```
signatory_name: Dr. Ahmad Marifi (required)
signatory_title: Instructor (required)
signature_image: [File] PNG/JPG max 2MB (required)
```

**Response 201:**

```json
{
    "message": "Signature added successfully.",
    "signature": {
        "id": 1,
        "signatory_name": "Dr. Ahmad Marifi",
        "signatory_title": "Instructor",
        "signature_url": "http://localhost:8000/storage/signatures/abc.png",
        "order": 1
    }
}
```

---

### 48. Admin - Update Signature

```http
PUT /api/admin/courses/{courseId}/signatures/{signatureId}
Authorization: Bearer {admin_token}
Content-Type: multipart/form-data
```

**Body (form-data) - All optional:**

```
signatory_name: Updated Name
signatory_title: Updated Title
signature_image: [File] New signature image
```

**Response 200:**

```json
{
  "message": "Signature updated successfully.",
  "signature": {...}
}
```

---

### 49. Admin - Delete Signature

```http
DELETE /api/admin/courses/{courseId}/signatures/{signatureId}
Authorization: Bearer {admin_token}
```

**Response 200:**

```json
{
    "message": "Signature deleted successfully."
}
```

---

### 50. Admin - Reorder Signatures

```http
POST /api/admin/courses/{courseId}/signatures/reorder
Authorization: Bearer {admin_token}
Content-Type: application/json
```

**Body:**

```json
{
    "signatures": [
        { "id": 2, "order": 1 },
        { "id": 1, "order": 2 },
        { "id": 3, "order": 3 }
    ]
}
```

**Response 200:**

```json
{
    "status": "success",
    "message": "Signatures reordered successfully."
}
```

---

## 📝 Validation Rules Summary

### Course

- `title`: required, max 255
- `price`: required, numeric, min 0
- `instructor_name`: required
- `thumbnail`: image, max 2MB
- `status`: draft | published

### Section

- `title`: required, string

### Lesson

- `title`: required, max 255
- `type`: required (video | document | text | quiz)
- `content_source`: required for video/document (upload | external)
- `content_file`: required if upload, video max 500MB, document max 500MB
- `content_url`: required if external, must be valid URL
- `content_url` (video): must be YouTube URL pattern
- `content_text`: required for text type

### Question

- `question_text`: required
- `points`: required, integer, min 1
- `sequence`: optional, integer
- `options`: required, array, min 2
- `options.*.option_text`: required
- `options.*.is_correct`: required, boolean

### Certificate Config

- `template_type`: classic | modern | elegant
- `logo`: image, max 2MB
- `background_image`: image, max 5MB
- `primary_color`: hex color code
- `secondary_color`: hex color code

### Certificate Signature

- `signatory_name`: required, max 255
- `signatory_title`: required, max 255
- `signature_image`: required (create), image, max 2MB

---

## 🔄 Complete Flow Example

### Student Learning Flow

```bash
# 1. Register/Login
POST /api/auth/register
POST /api/auth/login

# 2. Browse Courses
GET /api/courses

# 3. View Course Detail
GET /api/courses/{slug}

# 4. Enroll Course
POST /api/courses/1/enroll

# 5. View My Courses
GET /api/my-courses

# 6. Start Learning
GET /api/lessons/1

# 7. Complete Video Lesson
POST /api/lessons/1/complete

# 8. Take Quiz
GET /api/lessons/5/questions/1
GET /api/lessons/5/questions/2
POST /api/lessons/5/submit-quiz

# 9. View Quiz Results
GET /api/quiz-attempts/42/review

# 10. Get Certificate
GET /api/my-certificates
GET /api/certificates/1/download
```

### Admin Course Creation Flow

```bash
# 1. Login as Admin
POST /api/auth/login

# 2. Create Course
POST /api/admin/courses

# 3. Add Sections
POST /api/admin/courses/1/sections

# 4. Add Lessons
POST /api/admin/sections/1/lessons (video)
POST /api/admin/sections/1/lessons (quiz)

# 5. Build Quiz
POST /api/admin/lessons/5/questions (add question 1)
POST /api/admin/lessons/5/questions (add question 2)
POST /api/admin/lessons/5/questions (add question 3)

# 6. Setup Certificate
POST /api/admin/courses/1/certificate-config
POST /api/admin/courses/1/signatures

# 7. Publish Course
PUT /api/admin/courses/1 (status: published)
```

---

## ⚠️ Error Codes

- `400`: Bad Request (validation error)
- `401`: Unauthorized (invalid/missing token)
- `403`: Forbidden (not admin)
- `404`: Not Found
- `422`: Validation Failed
- `500`: Internal Server Error

---

## 🎯 Total Endpoints: 51

- **Auth**: 6 endpoints
- **Public**: 3 endpoints (termasuk certificate preview)
- **Student**: 13 endpoints
- **Admin Course**: 5 endpoints
- **Admin Content**: 15 endpoints
- **Admin Certificate**: 9 endpoints

---

**Verified from actual code:** ✅ Semua endpoint diverifikasi dari `routes/api.php` dan controllers yang sebenarnya.

Ready to integrate! 🚀
