{
  "info": {
    "_postman_id": "defect-types-api-collection-2026",
    "name": "Defect Types API - CRUD Operations",
    "description": "Complete CRUD API for managing Maintenance Defect Types.\n\nThis collection allows you to:\n- Create, read, update, and delete defect types\n- Link defect types to areas of expertise (asset types) and scope of work\n- Search and filter defect types\n- Toggle active/inactive status\n\nDefect types enable automatic routing of requests to the correct technician and accurate pricing based on expertise and scope.",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
    "_exporter_id": "12345"
  },
  "variable": [
    {
      "key": "BASE_URL",
      "value": "http://127.0.0.1:8001/api/v1",
      "type": "string"
    },
    {
      "key": "TOKEN",
      "value": "",
      "type": "string",
      "description": "Bearer token for authentication"
    },
    {
      "key": "DEFECT_TYPE_ID",
      "value": "1",
      "type": "string",
      "description": "Defect Type ID for testing"
    },
    {
      "key": "ASSET_TYPE_ID",
      "value": "1",
      "type": "string",
      "description": "Asset Type ID (Area of Expertise)"
    },
    {
      "key": "SCOPE_OF_WORK_ID",
      "value": "1",
      "type": "string",
      "description": "Scope of Work ID"
    }
  ],
  "item": [
    {
      "name": "Defect Types Operations",
      "item": [
        {
          "name": "Get All Defect Types",
          "request": {
            "method": "GET",
            "header": [
              {
                "key": "Accept",
                "value": "application/json",
                "type": "text"
              },
              {
                "key": "Authorization",
                "value": "Bearer {{TOKEN}}",
                "type": "text"
              }
            ],
            "url": {
              "raw": "{{BASE_URL}}/maintenance/defect-types?page=1&per_page=15",
              "host": [
                "{{BASE_URL}}"
              ],
              "path": [
                "maintenance",
                "defect-types"
              ],
              "query": [
                {
                  "key": "page",
                  "value": "1",
                  "description": "Page number"
                },
                {
                  "key": "per_page",
                  "value": "15",
                  "description": "Items per page"
                }
              ]
            },
            "description": "Get all defect types with pagination. Returns defect types with their linked area of expertise (asset type) and scope of work."
          },
          "response": [
            {
              "name": "Success Response",
              "originalRequest": {
                "method": "GET",
                "header": [],
                "url": {
                  "raw": "{{BASE_URL}}/maintenance/defect-types?page=1&per_page=15",
                  "host": [
                    "{{BASE_URL}}"
                  ],
                  "path": [
                    "maintenance",
                    "defect-types"
                  ]
                }
              },
              "status": "OK",
              "code": 200,
              "_postman_previewlanguage": "json",
              "header": [],
              "cookie": [],
              "body": "{\n    \"success\": true,\n    \"message\": \"Defect types retrieved successfully.\",\n    \"data\": {\n        \"current_page\": 1,\n        \"data\": [\n            {\n                \"id\": 1,\n                \"name\": \"Electrical Fault\",\n                \"description\": \"Issues related to electrical systems\",\n                \"area_of_expertise\": {\n                    \"id\": 5,\n                    \"name\": \"HVAC Systems\",\n                    \"code\": \"HVAC-001\"\n                },\n                \"area_of_expertise_id\": 5,\n                \"scope_of_work\": {\n                    \"id\": 2,\n                    \"name\": \"Repair\"\n                },\n                \"scope_of_work_id\": 2,\n                \"is_active\": true,\n                \"created_at\": \"2026-02-04T12:00:00.000000Z\",\n                \"updated_at\": \"2026-02-04T12:00:00.000000Z\",\n                \"deleted_at\": null\n            }\n        ],\n        \"first_page_url\": \"...\",\n        \"from\": 1,\n        \"last_page\": 1,\n        \"last_page_url\": \"...\",\n        \"links\": [...],\n        \"next_page_url\": null,\n        \"path\": \"...\",\n        \"per_page\": 15,\n        \"prev_page_url\": null,\n        \"to\": 1,\n        \"total\": 1\n    }\n}"
            }
          ]
        },
        {
          "name": "Get Active Defect Types",
          "request": {
            "method": "GET",
            "header": [
              {
                "key": "Accept",
                "value": "application/json",
                "type": "text"
              },
              {
                "key": "Authorization",
                "value": "Bearer {{TOKEN}}",
                "type": "text"
              }
            ],
            "url": {
              "raw": "{{BASE_URL}}/maintenance/defect-types/active?page=1&per_page=15",
              "host": [
                "{{BASE_URL}}"
              ],
              "path": [
                "maintenance",
                "defect-types",
                "active"
              ],
              "query": [
                {
                  "key": "page",
                  "value": "1"
                },
                {
                  "key": "per_page",
                  "value": "15"
                }
              ]
            },
            "description": "Get all active defect types with pagination. Only returns defect types where is_active = true."
          },
          "response": []
        },
        {
          "name": "Search Defect Types",
          "request": {
            "method": "GET",
            "header": [
              {
                "key": "Accept",
                "value": "application/json",
                "type": "text"
              },
              {
                "key": "Authorization",
                "value": "Bearer {{TOKEN}}",
                "type": "text"
              }
            ],
            "url": {
              "raw": "{{BASE_URL}}/maintenance/defect-types/search?q=electrical&page=1&per_page=15",
              "host": [
                "{{BASE_URL}}"
              ],
              "path": [
                "maintenance",
                "defect-types",
                "search"
              ],
              "query": [
                {
                  "key": "q",
                  "value": "electrical",
                  "description": "Search query - searches in name and description"
                },
                {
                  "key": "page",
                  "value": "1"
                },
                {
                  "key": "per_page",
                  "value": "15"
                }
              ]
            },
            "description": "Search defect types by name or description. Returns paginated results matching the search query."
          },
          "response": []
        },
        {
          "name": "Get Single Defect Type",
          "request": {
            "method": "GET",
            "header": [
              {
                "key": "Accept",
                "value": "application/json",
                "type": "text"
              },
              {
                "key": "Authorization",
                "value": "Bearer {{TOKEN}}",
                "type": "text"
              }
            ],
            "url": {
              "raw": "{{BASE_URL}}/maintenance/defect-types/{{DEFECT_TYPE_ID}}",
              "host": [
                "{{BASE_URL}}"
              ],
              "path": [
                "maintenance",
                "defect-types",
                "{{DEFECT_TYPE_ID}}"
              ]
            },
            "description": "Get a single defect type by ID with its relationships (area of expertise and scope of work)."
          },
          "response": [
            {
              "name": "Success Response",
              "originalRequest": {
                "method": "GET",
                "header": [],
                "url": {
                  "raw": "{{BASE_URL}}/maintenance/defect-types/1",
                  "host": [
                    "{{BASE_URL}}"
                  ],
                  "path": [
                    "maintenance",
                    "defect-types",
                    "1"
                  ]
                }
              },
              "status": "OK",
              "code": 200,
              "_postman_previewlanguage": "json",
              "header": [],
              "cookie": [],
              "body": "{\n    \"success\": true,\n    \"message\": \"Defect type retrieved successfully.\",\n    \"data\": {\n        \"id\": 1,\n        \"name\": \"Electrical Fault\",\n        \"description\": \"Issues related to electrical systems\",\n        \"area_of_expertise\": {\n            \"id\": 5,\n            \"name\": \"HVAC Systems\",\n            \"code\": \"HVAC-001\"\n        },\n        \"area_of_expertise_id\": 5,\n        \"scope_of_work\": {\n            \"id\": 2,\n            \"name\": \"Repair\"\n        },\n        \"scope_of_work_id\": 2,\n        \"is_active\": true,\n        \"created_at\": \"2026-02-04T12:00:00.000000Z\",\n        \"updated_at\": \"2026-02-04T12:00:00.000000Z\",\n        \"deleted_at\": null\n    }\n}"
            }
          ]
        },
        {
          "name": "Create Defect Type",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Accept",
                "value": "application/json",
                "type": "text"
              },
              {
                "key": "Authorization",
                "value": "Bearer {{TOKEN}}",
                "type": "text"
              },
              {
                "key": "Content-Type",
                "value": "application/json",
                "type": "text"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n    \"name\": \"Mechanical Failure\",\n    \"description\": \"Issues related to mechanical components and systems\",\n    \"area_of_expertise_id\": {{ASSET_TYPE_ID}},\n    \"scope_of_work_id\": {{SCOPE_OF_WORK_ID}},\n    \"is_active\": true\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": {
              "raw": "{{BASE_URL}}/maintenance/defect-types",
              "host": [
                "{{BASE_URL}}"
              ],
              "path": [
                "maintenance",
                "defect-types"
              ]
            },
            "description": "Create a new defect type. Links the defect type to an area of expertise (asset type) and scope of work for automatic routing and pricing."
          },
          "response": [
            {
              "name": "Success Response",
              "originalRequest": {
                "method": "POST",
                "header": [],
                "body": {
                  "mode": "raw",
                  "raw": "{\n    \"name\": \"Mechanical Failure\",\n    \"description\": \"Issues related to mechanical components\",\n    \"area_of_expertise_id\": 1,\n    \"scope_of_work_id\": 1,\n    \"is_active\": true\n}",
                  "options": {
                    "raw": {
                      "language": "json"
                    }
                  }
                },
                "url": {
                  "raw": "{{BASE_URL}}/maintenance/defect-types",
                  "host": [
                    "{{BASE_URL}}"
                  ],
                  "path": [
                    "maintenance",
                    "defect-types"
                  ]
                }
              },
              "status": "Created",
              "code": 201,
              "_postman_previewlanguage": "json",
              "header": [],
              "cookie": [],
              "body": "{\n    \"success\": true,\n    \"message\": \"Defect type created successfully.\",\n    \"data\": {\n        \"id\": 2,\n        \"name\": \"Mechanical Failure\",\n        \"description\": \"Issues related to mechanical components and systems\",\n        \"area_of_expertise\": {\n            \"id\": 1,\n            \"name\": \"Elevators\",\n            \"code\": \"ELEV-001\"\n        },\n        \"area_of_expertise_id\": 1,\n        \"scope_of_work\": {\n            \"id\": 1,\n            \"name\": \"Maintenance\"\n        },\n        \"scope_of_work_id\": 1,\n        \"is_active\": true,\n        \"created_at\": \"2026-02-04T12:30:00.000000Z\",\n        \"updated_at\": \"2026-02-04T12:30:00.000000Z\",\n        \"deleted_at\": null\n    }\n}"
            },
            {
              "name": "Validation Error",
              "originalRequest": {
                "method": "POST",
                "header": [],
                "body": {
                  "mode": "raw",
                  "raw": "{\n    \"name\": \"\",\n    \"description\": \"Test\"\n}",
                  "options": {
                    "raw": {
                      "language": "json"
                    }
                  }
                },
                "url": {
                  "raw": "{{BASE_URL}}/maintenance/defect-types",
                  "host": [
                    "{{BASE_URL}}"
                  ],
                  "path": [
                    "maintenance",
                    "defect-types"
                  ]
                }
              },
              "status": "Unprocessable Entity",
              "code": 422,
              "_postman_previewlanguage": "json",
              "header": [],
              "cookie": [],
              "body": "{\n    \"success\": false,\n    \"message\": \"Validation failed\",\n    \"errors\": {\n        \"name\": [\n            \"Defect type name is required.\"\n        ]\n    }\n}"
            }
          ]
        },
        {
          "name": "Update Defect Type",
          "request": {
            "method": "PUT",
            "header": [
              {
                "key": "Accept",
                "value": "application/json",
                "type": "text"
              },
              {
                "key": "Authorization",
                "value": "Bearer {{TOKEN}}",
                "type": "text"
              },
              {
                "key": "Content-Type",
                "value": "application/json",
                "type": "text"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n    \"name\": \"Updated Mechanical Failure\",\n    \"description\": \"Updated description for mechanical issues\",\n    \"area_of_expertise_id\": {{ASSET_TYPE_ID}},\n    \"scope_of_work_id\": {{SCOPE_OF_WORK_ID}},\n    \"is_active\": false\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": {
              "raw": "{{BASE_URL}}/maintenance/defect-types/{{DEFECT_TYPE_ID}}",
              "host": [
                "{{BASE_URL}}"
              ],
              "path": [
                "maintenance",
                "defect-types",
                "{{DEFECT_TYPE_ID}}"
              ]
            },
            "description": "Update an existing defect type. All fields are optional - only provided fields will be updated."
          },
          "response": [
            {
              "name": "Success Response",
              "originalRequest": {
                "method": "PUT",
                "header": [],
                "body": {
                  "mode": "raw",
                  "raw": "{\n    \"name\": \"Updated Mechanical Failure\",\n    \"description\": \"Updated description\",\n    \"is_active\": false\n}",
                  "options": {
                    "raw": {
                      "language": "json"
                    }
                  }
                },
                "url": {
                  "raw": "{{BASE_URL}}/maintenance/defect-types/1",
                  "host": [
                    "{{BASE_URL}}"
                  ],
                  "path": [
                    "maintenance",
                    "defect-types",
                    "1"
                  ]
                }
              },
              "status": "OK",
              "code": 200,
              "_postman_previewlanguage": "json",
              "header": [],
              "cookie": [],
              "body": "{\n    \"success\": true,\n    \"message\": \"Defect type updated successfully.\",\n    \"data\": {\n        \"id\": 1,\n        \"name\": \"Updated Mechanical Failure\",\n        \"description\": \"Updated description\",\n        \"area_of_expertise\": {\n            \"id\": 1,\n            \"name\": \"Elevators\",\n            \"code\": \"ELEV-001\"\n        },\n        \"area_of_expertise_id\": 1,\n        \"scope_of_work\": {\n            \"id\": 1,\n            \"name\": \"Maintenance\"\n        },\n        \"scope_of_work_id\": 1,\n        \"is_active\": false,\n        \"created_at\": \"2026-02-04T12:00:00.000000Z\",\n        \"updated_at\": \"2026-02-04T12:45:00.000000Z\",\n        \"deleted_at\": null\n    }\n}"
            }
          ]
        },
        {
          "name": "Delete Defect Type",
          "request": {
            "method": "DELETE",
            "header": [
              {
                "key": "Accept",
                "value": "application/json",
                "type": "text"
              },
              {
                "key": "Authorization",
                "value": "Bearer {{TOKEN}}",
                "type": "text"
              }
            ],
            "url": {
              "raw": "{{BASE_URL}}/maintenance/defect-types/{{DEFECT_TYPE_ID}}",
              "host": [
                "{{BASE_URL}}"
              ],
              "path": [
                "maintenance",
                "defect-types",
                "{{DEFECT_TYPE_ID}}"
              ]
            },
            "description": "Delete a defect type (soft delete). The record will be marked as deleted but can be restored if needed."
          },
          "response": [
            {
              "name": "Success Response",
              "originalRequest": {
                "method": "DELETE",
                "header": [],
                "url": {
                  "raw": "{{BASE_URL}}/maintenance/defect-types/1",
                  "host": [
                    "{{BASE_URL}}"
                  ],
                  "path": [
                    "maintenance",
                    "defect-types",
                    "1"
                  ]
                }
              },
              "status": "OK",
              "code": 200,
              "_postman_previewlanguage": "json",
              "header": [],
              "cookie": [],
              "body": "{\n    \"success\": true,\n    \"message\": \"Defect type deleted successfully.\",\n    \"data\": null\n}"
            }
          ]
        },
        {
          "name": "Toggle Defect Type Status",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Accept",
                "value": "application/json",
                "type": "text"
              },
              {
                "key": "Authorization",
                "value": "Bearer {{TOKEN}}",
                "type": "text"
              }
            ],
            "url": {
              "raw": "{{BASE_URL}}/maintenance/defect-types/{{DEFECT_TYPE_ID}}/toggle-status",
              "host": [
                "{{BASE_URL}}"
              ],
              "path": [
                "maintenance",
                "defect-types",
                "{{DEFECT_TYPE_ID}}",
                "toggle-status"
              ]
            },
            "description": "Toggle the active status of a defect type. If currently active, it will be set to inactive and vice versa."
          },
          "response": [
            {
              "name": "Success Response",
              "originalRequest": {
                "method": "POST",
                "header": [],
                "url": {
                  "raw": "{{BASE_URL}}/maintenance/defect-types/1/toggle-status",
                  "host": [
                    "{{BASE_URL}}"
                  ],
                  "path": [
                    "maintenance",
                    "defect-types",
                    "1",
                    "toggle-status"
                  ]
                }
              },
              "status": "OK",
              "code": 200,
              "_postman_previewlanguage": "json",
              "header": [],
              "cookie": [],
              "body": "{\n    \"success\": true,\n    \"message\": \"Defect type status updated successfully.\",\n    \"data\": {\n        \"id\": 1,\n        \"name\": \"Mechanical Failure\",\n        \"description\": \"Issues related to mechanical components\",\n        \"area_of_expertise\": {\n            \"id\": 1,\n            \"name\": \"Elevators\",\n            \"code\": \"ELEV-001\"\n        },\n        \"area_of_expertise_id\": 1,\n        \"scope_of_work\": {\n            \"id\": 1,\n            \"name\": \"Maintenance\"\n        },\n        \"scope_of_work_id\": 1,\n        \"is_active\": false,\n        \"created_at\": \"2026-02-04T12:00:00.000000Z\",\n        \"updated_at\": \"2026-02-04T12:50:00.000000Z\",\n        \"deleted_at\": null\n    }\n}"
            }
          ]
        }
      ],
      "description": "Complete CRUD operations for managing defect types in the maintenance system."
    }
  ]
}
