openapi: 3.0.1
info:
  title: Nielsen Chase CRM - External API
  version: "1.0.0"
  description: |
    External integration API - Nielsen Chase CRM
    Bu OpenAPI dokümanı /api/external altındaki endpointleri tanımlar.
servers:
  - url: https://ncportal.tech/api/external
    description: Production server (örnek)
components:
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: X-API-Key
  schemas:
    Company:
      type: object
      properties:
        id:
          type: string
          format: uuid
        company_name:
          type: string
        contact_person_name:
          type: string
        contact_person_email:
          type: string
          format: email
        contact_person_phone:
          type: string
        contact_person_title:
          type: string
        company_address:
          type: string
        company_city:
          type: string
        company_district:
          type: string
        company_postal_code:
          type: string
        is_active:
          type: boolean
        created_at:
          type: string
          format: date-time
    Project:
      type: object
      properties:
        id:
          type: string
          format: uuid
        project_number:
          type: string
        name:
          type: string
        description:
          type: string
        status:
          type: string
        company_id:
          type: string
          format: uuid
        product_name:
          type: string
        product_details:
          type: string
        gtip_hs_code:
          type: string
        target_countries:
          type: array
          items:
            type: string
        excluded_countries:
          type: array
          items:
            type: string
          description: "Tercih edilmeyen/hariç tutulacak ülkeler"
        product_certificates:
          type: string
          description: "Ürün sertifikaları ve belgeler"
        capacity_report_url:
          type: string
          format: uri
          description: "Kapasite raporu URL'si"
        official_website_url:
          type: string
          format: uri
          description: "Resmi website URL'si"
        average_cost:
          type: number
          format: decimal
          description: "Ortalama maliyet"
        unit_cost:
          type: number
          format: decimal
          description: "Birim maliyet"
        priority:
          type: string
        currency:
          type: string
        start_date:
          type: string
          format: date
        end_date:
          type: string
          format: date
        created_at:
          type: string
          format: date-time
    ProjectFile:
      type: object
      properties:
        id:
          type: string
          format: uuid
        original_name:
          type: string
        filename:
          type: string
        file_type:
          type: string
        file_size:
          type: integer
        mime_type:
          type: string
        download_url:
          type: string
        created_at:
          type: string
          format: date-time
    SupportTicket:
      type: object
      properties:
        ticket_id:
          type: string
        ticket_number:
          type: string
        title:
          type: string
        status:
          type: string
    ErrorResponse:
      type: object
      properties:
        success:
          type: boolean
        error:
          type: string
        message:
          type: string
        messages:
          type: object
security:
  - ApiKeyAuth: []
paths:
  /companies:
    get:
      summary: Firma listesi
      description: Firma listesi. API key'in erişimine göre sonuçlar filtrelenir.
      parameters:
        - in: query
          name: search
          schema:
            type: string
        - in: query
          name: is_active
          schema:
            type: boolean
        - in: query
          name: limit
          schema:
            type: integer
            default: 50
        - in: query
          name: offset
          schema:
            type: integer
            default: 0
      responses:
        '200':
          description: Başarılı
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                  data:
                    type: array
                    items:
                      $ref: '#/components/schemas/Company'
    post:
      summary: Yeni firma oluştur
      description: Yeni şirket kaydı oluşturur. Contact person email benzersizdir.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [company_name, contact_person_name, contact_person_email, contact_person_phone, company_address, company_city]
              properties:
                company_name:
                  type: string
                contact_person_name:
                  type: string
                contact_person_email:
                  type: string
                  format: email
                contact_person_phone:
                  type: string
                contact_person_title:
                  type: string
                company_address:
                  type: string
                company_district:
                  type: string
                company_city:
                  type: string
                company_postal_code:
                  type: string
                is_active:
                  type: boolean
      responses:
        '201':
          description: Company created
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                  message:
                    type: string
                  data:
                    $ref: '#/components/schemas/Company'
        '409':
          description: Email already exists
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '422':
          description: Validation failed
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
  /projects:
    get:
      summary: Proje listesi
      parameters:
        - in: query
          name: status
          schema:
            type: string
            enum: [draft, pending, in_production, completed, cancelled]
        - in: query
          name: user_email
          schema:
            type: string
            format: email
        - in: query
          name: company_id
          schema:
            type: string
            format: uuid
        - in: query
          name: date_from
          schema:
            type: string
            format: date
        - in: query
          name: date_to
          schema:
            type: string
            format: date
        - in: query
          name: limit
          schema:
            type: integer
            default: 50
        - in: query
          name: offset
          schema:
            type: integer
            default: 0
      responses:
        '200':
          description: Başarılı
    post:
      summary: Proje oluştur
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [name, company_id, product_name]
              properties:
                name:
                  type: string
                description:
                  type: string
                company_id:
                  type: string
                  format: uuid
                product_name:
                  type: string
                product_details:
                  type: string
                gtip_hs_code:
                  type: string
                target_countries:
                  type: array
                  items:
                    type: string
                excluded_countries:
                  type: array
                  items:
                    type: string
                  description: "Tercih edilmeyen ülkeler"
                product_certificates:
                  type: string
                  description: "Ürün sertifikaları ve belgeler"
                capacity_report_url:
                  type: string
                  format: uri
                  description: "Kapasite raporu URL'si"
                official_website_url:
                  type: string
                  format: uri
                  description: "Resmi website URL'si"
                average_cost:
                  type: number
                  format: decimal
                  description: "Ortalama maliyet"
                unit_cost:
                  type: number
                  format: decimal
                  description: "Birim maliyet"
                currency:
                  type: string
                  enum: [USD, EUR, TRY, GBP]
                project_type:
                  type: string
                priority:
                  type: string
                  enum: [low, medium, high, urgent]
                start_date:
                  type: string
                  format: date
                end_date:
                  type: string
                  format: date
                metadata:
                  type: object
      responses:
        '201':
          description: Proje oluşturuldu
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                  data:
                    $ref: '#/components/schemas/Project'
  /projects/{projectId}:
    get:
      summary: Proje detayları
      parameters:
        - in: path
          name: projectId
          required: true
          schema:
            type: string
            format: uuid
      responses:
        '200':
          description: Başarılı
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                  data:
                    $ref: '#/components/schemas/Project'
        '404':
          description: Not found
  /projects/{projectId}/status:
    put:
      summary: Proje durumu güncelle
      parameters:
        - in: path
          name: projectId
          required: true
          schema:
            type: string
            format: uuid
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [status]
              properties:
                status:
                  type: string
                  enum: [draft, pending, in_production, completed, cancelled]
                notes:
                  type: string
                completed_files:
                  type: array
                  items:
                    type: string
                notification_data:
                  type: object
      responses:
        '200':
          description: Updated
  /projects/{projectId}/approve:
    post:
      summary: Proje onayla
      parameters:
        - in: path
          name: projectId
          required: true
          schema:
            type: string
            format: uuid
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                approved:
                  type: boolean
                approval_notes:
                  type: string
                revision_requests:
                  type: array
                  items:
                    type: string
      responses:
        '200':
          description: Approved
  /projects/{projectId}/files:
    get:
      summary: Proje dosyalarını listele
      parameters:
        - in: path
          name: projectId
          required: true
          schema:
            type: string
            format: uuid
        - in: query
          name: file_type
          schema:
            type: string
            enum: [document, image, certificate, report, other]
        - in: query
          name: include_metadata
          schema:
            type: boolean
      responses:
        '200':
          description: Files list
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                  data:
                    type: object
                    properties:
                      project:
                        $ref: '#/components/schemas/Project'
                      files:
                        type: array
                        items:
                          $ref: '#/components/schemas/ProjectFile'
    post:
      summary: Projeye dosya yükle
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              type: object
              required: [file, file_type]
              properties:
                file:
                  type: string
                  format: binary
                file_type:
                  type: string
                  enum: [analysis_result, certificate, report, other]
                description:
                  type: string
                is_final:
                  type: boolean
      responses:
        '200':
          description: File uploaded
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                  data:
                    type: object
                    properties:
                      file_id:
                        type: string
                      original_name:
                        type: string
  /projects/{projectId}/files/{fileId}/download:
    get:
      summary: Proje dosyası indir
      parameters:
        - in: path
          name: projectId
          required: true
          schema:
            type: string
        - in: path
          name: fileId
          required: true
          schema:
            type: string
      responses:
        '200':
          description: File stream
        '404':
          description: File not found
  /subscriptions:
    get:
      summary: Abonelik detayları
      parameters:
        - in: query
          name: user_id
          schema:
            type: string
            format: uuid
        - in: query
          name: email
          schema:
            type: string
            format: email
      responses:
        '200':
          description: Subscription details
  /support/tickets:
    get:
      summary: Destek taleplerini listele
      parameters:
        - in: query
          name: status
          schema:
            type: string
        - in: query
          name: user_id
          schema:
            type: string
            format: uuid
        - in: query
          name: limit
          schema:
            type: integer
            default: 50
        - in: query
          name: offset
          schema:
            type: integer
            default: 0
      responses:
        '200':
          description: Tickets list
    post:
      summary: Destek talebi oluştur
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [user_id, title, description]
              properties:
                user_id:
                  type: string
                  format: uuid
                title:
                  type: string
                description:
                  type: string
                priority:
                  type: string
                  enum: [low, medium, high]
                category:
                  type: string
      responses:
        '201':
          description: Ticket created
  /support/tickets/{ticketId}/status:
    put:
      summary: Destek talebi durumu güncelle
      parameters:
        - in: path
          name: ticketId
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                status:
                  type: string
      responses:
        '200':
          description: Updated
