{
	"openapi": "3.0.3",
	"info": {
		"title": "FastEntegre API v2",
		"version": "2.0.0",
		"description": "Satıcı entegrasyon API’si (ERP/WMS). Bearer token: POST /oauth/token. Scope gönderilmezse veya users.apiTokenScopes boşsa token tüm KnownScopes’a sahiptir. expires_in döner fakat süre kesilmez; yeni token eskisini ezer. ApiController (Basic Auth, /api) deprecated’dir."
	},
	"servers": [
		{
			"url": "https://fastentegre.com",
			"description": "Production"
		}
	],
	"tags": [
		{"name": "Auth"},
		{"name": "Orders"},
		{"name": "Products"},
		{"name": "Stock"},
		{"name": "Invoices"},
		{"name": "Shipments"},
		{"name": "Stores"},
		{"name": "Customers"},
		{"name": "Docs"}
	],
	"paths": {
		"/oauth/token": {
			"post": {
				"tags": ["Auth"],
				"summary": "Password grant — Bearer token",
				"security": [],
				"requestBody": {
					"required": true,
					"content": {
						"application/x-www-form-urlencoded": {
							"schema": {"$ref": "#/components/schemas/TokenRequest"}
						},
						"application/json": {
							"schema": {"$ref": "#/components/schemas/TokenRequest"}
						}
					}
				},
				"responses": {
					"200": {
						"description": "Token",
						"content": {
							"application/json": {
								"schema": {"$ref": "#/components/schemas/TokenResponse"}
							}
						}
					},
					"400": {
						"description": "OAuth error",
						"content": {
							"application/json": {
								"schema": {"$ref": "#/components/schemas/OAuthError"}
							}
						}
					}
				}
			}
		},
		"/apiV2/openapi.json": {
			"get": {
				"tags": ["Docs"],
				"summary": "OpenAPI 3 spec",
				"security": [],
				"responses": {
					"200": {
						"description": "OpenAPI JSON"
					}
				}
			}
		},
		"/apiV2/docs": {
			"get": {
				"tags": ["Docs"],
				"summary": "Swagger UI",
				"security": [],
				"responses": {
					"200": {
						"description": "HTML"
					}
				}
			}
		},
		"/apiV2/order": {
			"get": {
				"tags": ["Orders"],
				"summary": "Sipariş listesi",
				"security": [{"oauth2": ["orders:read"], "bearer": ["orders:read"]}],
				"parameters": [
					{"$ref": "#/components/parameters/Page"},
					{"$ref": "#/components/parameters/OrderStatus"},
					{"$ref": "#/components/parameters/OrderStartDate"},
					{"$ref": "#/components/parameters/OrderEndDate"},
					{"$ref": "#/components/parameters/CreatedStartDate"},
					{"$ref": "#/components/parameters/CreatedEndDate"},
					{"$ref": "#/components/parameters/EditedStartDate"},
					{"$ref": "#/components/parameters/EditedEndDate"},
					{"$ref": "#/components/parameters/OrderBy"},
					{"$ref": "#/components/parameters/OrderByDesc"},
					{"$ref": "#/components/parameters/MainStoreId"}
				],
				"responses": {
					"200": {"$ref": "#/components/responses/ListSuccess"},
					"401": {"$ref": "#/components/responses/Unauthorized"},
					"403": {"$ref": "#/components/responses/InsufficientScope"}
				}
			}
		},
		"/apiV2/order/{id}": {
			"get": {
				"tags": ["Orders"],
				"summary": "Sipariş (orderId, platformShipmentCode veya diğer kimlik)",
				"security": [{"oauth2": ["orders:read"], "bearer": ["orders:read"]}],
				"parameters": [{"$ref": "#/components/parameters/IdPath"}],
				"responses": {
					"200": {"$ref": "#/components/responses/ItemSuccess"},
					"404": {"$ref": "#/components/responses/NotFound"},
					"403": {"$ref": "#/components/responses/InsufficientScope"}
				}
			}
		},
		"/apiV2/product": {
			"get": {
				"tags": ["Products"],
				"summary": "Ürün listesi",
				"security": [{"oauth2": ["products:read"], "bearer": ["products:read"]}],
				"parameters": [
					{"$ref": "#/components/parameters/Page"},
					{"$ref": "#/components/parameters/Sku"},
					{"$ref": "#/components/parameters/MainStoreId"},
					{"$ref": "#/components/parameters/CreatedStartDate"},
					{"$ref": "#/components/parameters/OrderBy"}
				],
				"responses": {
					"200": {"$ref": "#/components/responses/ListSuccess"},
					"403": {"$ref": "#/components/responses/InsufficientScope"}
				}
			}
		},
		"/apiV2/product/{id}": {
			"get": {
				"tags": ["Products"],
				"summary": "Ürün detay (productId)",
				"security": [{"oauth2": ["products:read"], "bearer": ["products:read"]}],
				"parameters": [{"$ref": "#/components/parameters/IdPath"}],
				"responses": {
					"200": {"$ref": "#/components/responses/ItemSuccess"},
					"404": {"$ref": "#/components/responses/NotFound"}
				}
			},
			"post": {
				"tags": ["Products"],
				"summary": "Toplu ürün oluştur (path id = mainStoreId)",
				"security": [{"oauth2": ["products:write"], "bearer": ["products:write"]}],
				"parameters": [{"$ref": "#/components/parameters/IdPath"}],
				"requestBody": {
					"required": true,
					"content": {
						"application/json": {
							"schema": {
								"type": "array",
								"items": {"$ref": "#/components/schemas/ProductCreate"}
							}
						}
					}
				},
				"responses": {
					"200": {"$ref": "#/components/responses/ItemSuccess"},
					"403": {"$ref": "#/components/responses/InsufficientScope"}
				}
			}
		},
		"/apiV2/stock": {
			"get": {
				"tags": ["Stock"],
				"summary": "Satılabilir stok listesi (varyant/sanal ürün)",
				"security": [{"oauth2": ["stock:read"], "bearer": ["stock:read"]}],
				"parameters": [
					{"$ref": "#/components/parameters/Page"},
					{"$ref": "#/components/parameters/Sku"},
					{"name": "productId", "in": "query", "schema": {"type": "integer"}},
					{"name": "locationId", "in": "query", "schema": {"type": "integer"}},
					{"$ref": "#/components/parameters/MainStoreId"}
				],
				"responses": {
					"200": {"$ref": "#/components/responses/ListSuccess"},
					"403": {"$ref": "#/components/responses/InsufficientScope"}
				}
			}
		},
		"/apiV2/stock/{id}": {
			"get": {
				"tags": ["Stock"],
				"summary": "Tek ürün satılabilir stok",
				"security": [{"oauth2": ["stock:read"], "bearer": ["stock:read"]}],
				"parameters": [
					{"$ref": "#/components/parameters/IdPath"},
					{"name": "locationId", "in": "query", "schema": {"type": "integer"}}
				],
				"responses": {
					"200": {"$ref": "#/components/responses/ItemSuccess"},
					"404": {"$ref": "#/components/responses/NotFound"}
				}
			}
		},
		"/apiV2/updateStock": {
			"post": {
				"tags": ["Stock"],
				"summary": "Toplu stok (ve isteğe bağlı fiyat) güncelle",
				"security": [{"oauth2": ["stock:write"], "bearer": ["stock:write"]}],
				"requestBody": {
					"required": true,
					"content": {
						"application/json": {
							"schema": {"$ref": "#/components/schemas/UpdateStockRequest"}
						}
					}
				},
				"responses": {
					"200": {
						"description": "Güncelleme özeti",
						"content": {
							"application/json": {
								"schema": {"$ref": "#/components/schemas/UpdateStockResponse"}
							}
						}
					},
					"403": {"$ref": "#/components/responses/InsufficientScope"}
				}
			}
		},
		"/apiV2/invoice": {
			"get": {
				"tags": ["Invoices"],
				"summary": "Fatura listesi",
				"security": [{"oauth2": ["orders:invoice"], "bearer": ["orders:invoice"]}],
				"parameters": [{"$ref": "#/components/parameters/Page"}, {"$ref": "#/components/parameters/CreatedStartDate"}],
				"responses": {"200": {"$ref": "#/components/responses/ListSuccess"}}
			}
		},
		"/apiV2/invoice/{id}": {
			"get": {
				"tags": ["Invoices"],
				"summary": "Fatura detay",
				"security": [{"oauth2": ["orders:invoice"], "bearer": ["orders:invoice"]}],
				"parameters": [{"$ref": "#/components/parameters/IdPath"}],
				"responses": {"200": {"$ref": "#/components/responses/ItemSuccess"}, "404": {"$ref": "#/components/responses/NotFound"}}
			}
		},
		"/apiV2/shipment": {
			"get": {
				"tags": ["Shipments"],
				"summary": "Kargo listesi",
				"security": [{"oauth2": ["orders:shipment"], "bearer": ["orders:shipment"]}],
				"parameters": [{"$ref": "#/components/parameters/Page"}],
				"responses": {"200": {"$ref": "#/components/responses/ListSuccess"}}
			}
		},
		"/apiV2/shipment/{id}": {
			"get": {
				"tags": ["Shipments"],
				"summary": "Kargo detay",
				"security": [{"oauth2": ["orders:shipment"], "bearer": ["orders:shipment"]}],
				"parameters": [{"$ref": "#/components/parameters/IdPath"}],
				"responses": {"200": {"$ref": "#/components/responses/ItemSuccess"}, "404": {"$ref": "#/components/responses/NotFound"}}
			}
		},
		"/apiV2/sendShipment/{platformShipmentCode}": {
			"post": {
				"tags": ["Shipments"],
				"summary": "Kargo gönderimini tetikle",
				"security": [{"oauth2": ["orders:shipment"], "bearer": ["orders:shipment"]}],
				"parameters": [{"name": "platformShipmentCode", "in": "path", "required": true, "schema": {"type": "string"}}],
				"responses": {
					"200": {"$ref": "#/components/responses/ActionSuccess"},
					"405": {"$ref": "#/components/responses/MethodNotAllowed"}
				}
			}
		},
		"/apiV2/sendInvoice/{platformShipmentCode}": {
			"post": {
				"tags": ["Invoices"],
				"summary": "e-Fatura gönderimini tetikle",
				"security": [{"oauth2": ["orders:invoice"], "bearer": ["orders:invoice"]}],
				"parameters": [{"name": "platformShipmentCode", "in": "path", "required": true, "schema": {"type": "string"}}],
				"responses": {"200": {"$ref": "#/components/responses/ActionSuccess"}}
			}
		},
		"/apiV2/productAcceptance": {
			"get": {
				"tags": ["Stock"],
				"summary": "Mal kabul listesi",
				"security": [{"oauth2": ["stock:read"], "bearer": ["stock:read"]}],
				"parameters": [{"$ref": "#/components/parameters/Page"}],
				"responses": {"200": {"$ref": "#/components/responses/ListSuccess"}}
			}
		},
		"/apiV2/productAcceptance/{id}": {
			"get": {
				"tags": ["Stock"],
				"summary": "Mal kabul detay",
				"security": [{"oauth2": ["stock:read"], "bearer": ["stock:read"]}],
				"parameters": [{"$ref": "#/components/parameters/IdPath"}],
				"responses": {"200": {"$ref": "#/components/responses/ItemSuccess"}, "404": {"$ref": "#/components/responses/NotFound"}}
			}
		},
		"/apiV2/mainStore": {
			"get": {
				"tags": ["Stores"],
				"summary": "Ana mağaza listesi",
				"security": [{"oauth2": ["stores:read"], "bearer": ["stores:read"]}],
				"parameters": [{"$ref": "#/components/parameters/Page"}],
				"responses": {"200": {"$ref": "#/components/responses/ListSuccess"}}
			}
		},
		"/apiV2/mainStore/{id}": {
			"get": {
				"tags": ["Stores"],
				"summary": "Ana mağaza detay",
				"security": [{"oauth2": ["stores:read"], "bearer": ["stores:read"]}],
				"parameters": [{"$ref": "#/components/parameters/IdPath"}],
				"responses": {"200": {"$ref": "#/components/responses/ItemSuccess"}}
			}
		},
		"/apiV2/store": {
			"get": {
				"tags": ["Stores"],
				"summary": "Mağaza listesi",
				"security": [{"oauth2": ["stores:read"], "bearer": ["stores:read"]}],
				"parameters": [{"$ref": "#/components/parameters/Page"}],
				"responses": {"200": {"$ref": "#/components/responses/ListSuccess"}}
			}
		},
		"/apiV2/store/{id}": {
			"get": {
				"tags": ["Stores"],
				"summary": "Mağaza detay",
				"security": [{"oauth2": ["stores:read"], "bearer": ["stores:read"]}],
				"parameters": [{"$ref": "#/components/parameters/IdPath"}],
				"responses": {"200": {"$ref": "#/components/responses/ItemSuccess"}}
			}
		},
		"/apiV2/customer": {
			"get": {
				"tags": ["Customers"],
				"summary": "Müşteri listesi",
				"security": [{"oauth2": ["customers:read"], "bearer": ["customers:read"]}],
				"parameters": [{"$ref": "#/components/parameters/Page"}],
				"responses": {"200": {"$ref": "#/components/responses/ListSuccess"}}
			},
			"post": {
				"tags": ["Customers"],
				"summary": "Müşteri oluştur",
				"security": [{"oauth2": ["customers:write"], "bearer": ["customers:write"]}],
				"requestBody": {
					"required": true,
					"content": {
						"application/json": {
							"schema": {"$ref": "#/components/schemas/StakeholderCreate"}
						}
					}
				},
				"responses": {"200": {"$ref": "#/components/responses/ItemSuccess"}}
			}
		},
		"/apiV2/customer/{id}": {
			"get": {
				"tags": ["Customers"],
				"summary": "Müşteri detay",
				"security": [{"oauth2": ["customers:read"], "bearer": ["customers:read"]}],
				"parameters": [{"$ref": "#/components/parameters/IdPath"}],
				"responses": {"200": {"$ref": "#/components/responses/ItemSuccess"}, "404": {"$ref": "#/components/responses/NotFound"}}
			}
		},
		"/apiV2/supplier": {
			"get": {
				"tags": ["Customers"],
				"summary": "Tedarikçi listesi",
				"security": [{"oauth2": ["customers:read"], "bearer": ["customers:read"]}],
				"parameters": [{"$ref": "#/components/parameters/Page"}],
				"responses": {"200": {"$ref": "#/components/responses/ListSuccess"}}
			},
			"post": {
				"tags": ["Customers"],
				"summary": "Tedarikçi oluştur",
				"security": [{"oauth2": ["customers:write"], "bearer": ["customers:write"]}],
				"requestBody": {
					"required": true,
					"content": {
						"application/json": {
							"schema": {"$ref": "#/components/schemas/StakeholderCreate"}
						}
					}
				},
				"responses": {"200": {"$ref": "#/components/responses/ItemSuccess"}}
			}
		},
		"/apiV2/getProductByStoreProductCode/{code}/{mainStoreId}": {
			"get": {
				"tags": ["Products"],
				"summary": "Mağaza ürün kodu ile ürün",
				"security": [{"oauth2": ["products:read"], "bearer": ["products:read"]}],
				"parameters": [
					{"name": "code", "in": "path", "required": true, "schema": {"type": "string"}},
					{"name": "mainStoreId", "in": "path", "required": true, "schema": {"type": "integer"}}
				],
				"responses": {"200": {"$ref": "#/components/responses/ItemSuccess"}, "404": {"$ref": "#/components/responses/NotFound"}}
			}
		}
	},
	"components": {
		"securitySchemes": {
			"bearer": {
				"type": "http",
				"scheme": "bearer",
				"bearerFormat": "hex",
				"description": "Authorization: Bearer <access_token>"
			},
			"oauth2": {
				"type": "oauth2",
				"flows": {
					"password": {
						"tokenUrl": "/oauth/token",
						"scopes": {
							"orders:read": "Sipariş okuma",
							"orders:invoice": "Fatura okuma ve gönderme",
							"orders:shipment": "Kargo okuma ve gönderme",
							"products:read": "Ürün okuma",
							"products:write": "Ürün oluşturma",
							"stock:read": "Stok / mal kabul okuma",
							"stock:write": "Stok güncelleme (fiyat alanları dahil)",
							"customers:read": "Müşteri / tedarikçi okuma",
							"customers:write": "Müşteri / tedarikçi oluşturma",
							"stores:read": "Ana mağaza / mağaza okuma"
						}
					}
				}
			}
		},
		"parameters": {
			"Page": {"name": "page", "in": "query", "schema": {"type": "integer", "default": 1}},
			"IdPath": {"name": "id", "in": "path", "required": true, "schema": {"type": "string"}},
			"Sku": {"name": "sku", "in": "query", "schema": {"type": "string"}},
			"MainStoreId": {"name": "mainStoreId", "in": "query", "schema": {"type": "integer"}},
			"OrderStatus": {"name": "orderStatus", "in": "query", "schema": {"type": "integer"}},
			"OrderStartDate": {"name": "orderStartDate", "in": "query", "schema": {"type": "string"}},
			"OrderEndDate": {"name": "orderEndDate", "in": "query", "schema": {"type": "string"}},
			"CreatedStartDate": {"name": "createdStartDate", "in": "query", "schema": {"type": "string"}},
			"CreatedEndDate": {"name": "createdEndDate", "in": "query", "schema": {"type": "string"}},
			"EditedStartDate": {"name": "editedStartDate", "in": "query", "schema": {"type": "string"}},
			"EditedEndDate": {"name": "editedEndDate", "in": "query", "schema": {"type": "string"}},
			"OrderBy": {"name": "orderBy", "in": "query", "schema": {"type": "string"}},
			"OrderByDesc": {"name": "orderByDesc", "in": "query", "schema": {"type": "string"}}
		},
		"schemas": {
			"TokenRequest": {
				"type": "object",
				"required": ["username", "password"],
				"properties": {
					"username": {"type": "string"},
					"password": {"type": "string", "format": "password"},
					"scope": {"type": "string", "description": "Boşlukla ayrılmış KnownScopes. Yoksa tüm scope’lar (unrestricted)."}
				}
			},
			"TokenResponse": {
				"type": "object",
				"properties": {
					"access_token": {"type": "string"},
					"token_type": {"type": "string", "example": "Bearer"},
					"expires_in": {"type": "integer", "example": 3600, "description": "Dönülür; sunucu expiry uygulamaz."},
					"scope": {"type": "string"}
				}
			},
			"OAuthError": {
				"type": "object",
				"properties": {
					"error": {"type": "string"},
					"error_description": {"type": "string"}
				}
			},
			"ListEnvelope": {
				"type": "object",
				"properties": {
					"result": {"type": "string", "example": "success"},
					"content": {"type": "array", "items": {"type": "object", "additionalProperties": true}},
					"page": {"type": "integer"},
					"pageSize": {"type": "integer", "example": 50},
					"hasMore": {"type": "boolean"}
				}
			},
			"ItemEnvelope": {
				"type": "object",
				"properties": {
					"result": {"type": "string", "example": "success"},
					"content": {"type": "object", "additionalProperties": true}
				}
			},
			"ErrorEnvelope": {
				"type": "object",
				"properties": {
					"result": {"type": "string", "example": "danger"},
					"error": {"type": "string"},
					"message": {"type": "string"}
				}
			},
			"InsufficientScope": {
				"type": "object",
				"properties": {
					"error": {"type": "string", "example": "insufficient_scope"},
					"error_description": {"type": "string", "example": "orders:read"}
				}
			},
			"UpdateStockRequest": {
				"type": "object",
				"required": ["items"],
				"properties": {
					"items": {
						"type": "array",
						"items": {
							"type": "object",
							"required": ["quantity"],
							"properties": {
								"productId": {"type": "integer"},
								"sku": {"type": "string"},
								"quantity": {"type": "number"},
								"locationId": {"type": "integer"},
								"salePrice": {"type": "number"},
								"wholesalePrice": {"type": "number"},
								"costPrice": {"type": "number"}
							}
						}
					}
				}
			},
			"UpdateStockResponse": {
				"type": "object",
				"properties": {
					"result": {"type": "string", "example": "success"},
					"updated": {"type": "integer"},
					"errorProducts": {"type": "array", "items": {"type": "object"}}
				}
			},
			"ProductCreate": {
				"type": "object",
				"additionalProperties": true,
				"properties": {
					"productName": {"type": "string"},
					"productSku": {"type": "string"},
					"variants": {"type": "array", "items": {"type": "object", "additionalProperties": true}}
				}
			},
			"StakeholderCreate": {
				"type": "object",
				"required": ["name", "address", "taxHouse", "taxId"],
				"properties": {
					"name": {"type": "string"},
					"address": {"type": "string"},
					"taxHouse": {"type": "string"},
					"taxId": {"type": "string"},
					"phone": {"type": "string"},
					"email": {"type": "string"},
					"country": {"type": "string", "example": "TR"}
				}
			}
		},
		"responses": {
			"ListSuccess": {
				"description": "Sayfalı liste",
				"content": {"application/json": {"schema": {"$ref": "#/components/schemas/ListEnvelope"}}}
			},
			"ItemSuccess": {
				"description": "Tek kayıt",
				"content": {"application/json": {"schema": {"$ref": "#/components/schemas/ItemEnvelope"}}}
			},
			"ActionSuccess": {
				"description": "İşlem sonucu",
				"content": {"application/json": {"schema": {"type": "object", "additionalProperties": true}}}
			},
			"Unauthorized": {
				"description": "Geçersiz token",
				"content": {"application/json": {"schema": {"$ref": "#/components/schemas/ErrorEnvelope"}}}
			},
			"NotFound": {
				"description": "Bulunamadı",
				"content": {"application/json": {"schema": {"$ref": "#/components/schemas/ErrorEnvelope"}}}
			},
			"MethodNotAllowed": {
				"description": "Yalnızca POST",
				"content": {"application/json": {"schema": {"$ref": "#/components/schemas/ErrorEnvelope"}}}
			},
			"InsufficientScope": {
				"description": "Token scope yetersiz",
				"content": {"application/json": {"schema": {"$ref": "#/components/schemas/InsufficientScope"}}}
			}
		}
	}
}
