{
  "schemaVersion": "1.0",
  "metadata": {
    "id": "service_workspace",
    "title": "Servis çalışma alanı",
    "locale": "tr"
  },
  "compatibility": {
    "contract": "1.0",
    "requiredCapabilities": [
      "detail",
      "form",
      "lookup",
      "message",
      "navigate",
      "request",
      "table",
      "text",
      "auth_otp",
      "record_permissions",
      "lookup_multiple",
      "lookup_resolve",
      "lookup_filters"
    ]
  },
  "connections": {
    "crm": {
      "origin": "https://service.example.test"
    }
  },
  "operations": {
    "login": {
      "connection": "crm",
      "method": "POST",
      "path": "/sessions/password",
      "auth": "none",
      "response": {
        "data": "/data"
      },
      "body": {
        "identifier": {
          "kind": "binding",
          "source": "input",
          "pointer": "/phone"
        },
        "secret": {
          "kind": "binding",
          "source": "input",
          "pointer": "/password"
        }
      }
    },
    "refresh": {
      "connection": "crm",
      "method": "POST",
      "path": "/auth/refresh",
      "auth": "none",
      "response": {
        "data": "/data"
      },
      "body": {
        "refresh_token": {
          "kind": "binding",
          "source": "session",
          "pointer": "/refresh_token"
        }
      }
    },
    "me": {
      "connection": "crm",
      "method": "GET",
      "path": "/me",
      "auth": "session",
      "response": {
        "data": "/data"
      }
    },
    "customers_list": {
      "connection": "crm",
      "method": "GET",
      "path": "/customers",
      "auth": "session",
      "response": {
        "data": "/data"
      }
    },
    "customer_update": {
      "connection": "crm",
      "method": "PATCH",
      "path": "/customers/{id}",
      "auth": "session",
      "response": {
        "data": "/data",
        "fieldErrors": "/error/fields"
      },
      "pathParams": {
        "id": {
          "kind": "binding",
          "source": "record",
          "pointer": "/id"
        }
      },
      "body": {
        "name": {
          "kind": "binding",
          "source": "form",
          "pointer": "/name"
        },
        "company": {
          "kind": "binding",
          "source": "form",
          "pointer": "/company"
        }
      }
    },
    "companies_search": {
      "connection": "crm",
      "method": "GET",
      "path": "/companies",
      "auth": "session",
      "response": {
        "data": "/data",
        "nextCursor": "/next"
      },
      "query": {
        "q": {
          "kind": "binding",
          "source": "input",
          "pointer": "/search"
        },
        "branch_id": {
          "kind": "binding",
          "source": "input",
          "pointer": "/branch"
        }
      },
      "pagination": {
        "mode": "cursor",
        "parameter": "cursor",
        "pageSize": 25
      }
    },
    "settings_load": {
      "connection": "crm",
      "method": "GET",
      "path": "/settings",
      "auth": "session",
      "response": {
        "data": "/data"
      }
    },
    "settings_save": {
      "connection": "crm",
      "method": "PATCH",
      "path": "/settings",
      "auth": "session",
      "response": {
        "data": "/data",
        "fieldErrors": "/error/fields"
      },
      "body": {
        "title": {
          "kind": "binding",
          "source": "form",
          "pointer": "/title"
        }
      }
    },
    "logout": {
      "connection": "crm",
      "method": "POST",
      "path": "/auth/logout",
      "auth": "session",
      "response": {
        "data": "/data"
      },
      "body": {
        "refresh_token": {
          "kind": "binding",
          "source": "session",
          "pointer": "/refresh_token"
        }
      }
    },
    "code_request": {
      "connection": "crm",
      "method": "POST",
      "path": "/sessions/code",
      "auth": "none",
      "response": {
        "data": "/data"
      },
      "body": {
        "destination": {
          "kind": "binding",
          "source": "input",
          "pointer": "/phone"
        }
      }
    },
    "code_verify": {
      "connection": "crm",
      "method": "POST",
      "path": "/sessions/verify",
      "auth": "none",
      "response": {
        "data": "/data"
      },
      "body": {
        "destination": {
          "kind": "binding",
          "source": "input",
          "pointer": "/phone"
        },
        "passcode": {
          "kind": "binding",
          "source": "input",
          "pointer": "/code"
        },
        "challenge_id": {
          "kind": "binding",
          "source": "input",
          "pointer": "/challenge"
        }
      }
    },
    "company_resolve": {
      "connection": "crm",
      "method": "GET",
      "path": "/companies/{id}",
      "auth": "session",
      "response": {
        "data": "/data"
      },
      "pathParams": {
        "id": {
          "kind": "binding",
          "source": "input",
          "pointer": "/value"
        }
      }
    }
  },
  "auth": {
    "mode": "bearer",
    "connection": "crm",
    "login": "login",
    "refresh": "refresh",
    "me": "me",
    "tokenPointer": "/data/access_token",
    "refreshTokenPointer": "/data/refresh_token",
    "header": "Authorization",
    "prefix": "Bearer ",
    "subjectPointer": "/data/subject",
    "permissionsPointer": "/data/permissions",
    "tenantPointer": "/data/tenant",
    "logout": "logout",
    "inputs": {
      "phone": {
        "label": "Telefon veya kullanıcı adı",
        "keyboard": "phone",
        "required": true
      },
      "password": {
        "label": "Parola",
        "keyboard": "password",
        "required": true
      },
      "code": {
        "label": "Tek kullanımlık kod",
        "keyboard": "otp",
        "required": true
      }
    },
    "otp": {
      "request": "code_request",
      "verify": "code_verify",
      "identifierInput": "phone",
      "codeInput": "code",
      "challengePointer": "/challenge/id",
      "challengeInput": "challenge",
      "resendAfterSeconds": 60,
      "expiresAfterSeconds": 300
    }
  },
  "permissions": {
    "customers_read": "Müşterileri gör",
    "customers_write": "Müşterileri düzenle",
    "settings_write": "Şirket ayarlarını düzenle",
    "balance_read": "Bakiyeleri gör"
  },
  "rules": {
    "has_name": {
      "operator": "ne",
      "left": {
        "kind": "binding",
        "source": "form",
        "pointer": "/name"
      },
      "right": {
        "kind": "literal",
        "value": ""
      }
    }
  },
  "actions": {
    "save_customer": {
      "type": "request",
      "operation": "customer_update",
      "permission": "customers_write",
      "visibleWhen": "has_name",
      "next": "saved"
    },
    "saved": {
      "type": "message",
      "text": "Kaydedildi"
    },
    "edit_customer": {
      "type": "navigate",
      "view": "customer_edit",
      "permission": "customers_write",
      "label": "Kaydı düzenle",
      "placement": "record"
    }
  },
  "resources": {
    "customers": {
      "label": "Müşteriler",
      "list": "customers_list",
      "update": "customer_update",
      "access": {
        "read": "customers_read",
        "write": "customers_write"
      },
      "fields": {
        "name": {
          "type": "text",
          "label": "Ad",
          "required": true
        },
        "company": {
          "type": "lookup",
          "label": "Şirket",
          "lookup": {
            "operation": "companies_search",
            "mode": "search",
            "multiple": true,
            "minCharacters": 2,
            "debounceMs": 300,
            "valuePointer": "/id",
            "labelPointer": "/name",
            "resolveOperation": "company_resolve",
            "filters": {
              "branch": {
                "kind": "binding",
                "source": "record",
                "pointer": "/name"
              }
            }
          }
        }
      },
      "recordPermissions": {
        "readPointer": "/abilities/view",
        "updatePointer": "/abilities/edit",
        "deletePointer": "/abilities/remove"
      }
    }
  },
  "views": {
    "customers": {
      "type": "table",
      "title": "Müşteriler",
      "resource": "customers",
      "columns": [
        "name",
        "company"
      ],
      "actions": [
        "edit_customer"
      ]
    },
    "customer_edit": {
      "type": "form",
      "title": "Müşteriyi düzenle",
      "resource": "customers",
      "fields": [
        "name",
        "company"
      ],
      "actions": [
        "save_customer"
      ]
    },
    "customer_detail": {
      "type": "detail",
      "title": "Müşteri detayı",
      "resource": "customers",
      "fields": [
        "name",
        "company"
      ],
      "actions": [
        "edit_customer"
      ]
    }
  },
  "settings": {},
  "navigation": [
    {
      "label": "Müşteriler",
      "view": "customers",
      "permission": "customers_read"
    }
  ]
}
