openapi: 3.0.0
info:
  title: Client Location API
  description: API for managing client locations
  version: 1.0.0
servers:
  - url: https://api.repzo.me/v1
    description: Production server
security:
  - ApiKeyAuth: []
tags:
  - name: Client Location
    description: Client location management operations
paths:
  /client-location:
    get:
      tags:
        - Client Location
      summary: Get all client locations
      description: Retrieve a list of all client locations with optional filtering and pagination
      parameters:
        - name: page
          in: query
          description: Page number for pagination
          required: false
          schema:
            type: integer
            minimum: 1
            default: 1
        - name: per_page
          in: query
          description: Number of items per page
          required: false
          schema:
            type: integer
            minimum: 1
            maximum: 100
            default: 25
        - name: sort
          in: query
          description: Sort field
          required: false
          schema:
            type: string
        - name: company_namespace
          in: query
          description: Company namespace for filtering
          required: false
          schema:
            type: array
            items:
              type: string
        - name: client
          in: query
          description: Filter by client ID
          required: false
          schema:
            type: string
        - name: disabled
          in: query
          description: Filter by disabled status
          required: false
          schema:
            type: boolean
        - name: _id
          in: query
          description: Filter by ID
          required: false
          schema:
            type: array
            items:
              type: string
      responses:
        "200":
          description: Successful response
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    type: array
                    items:
                      $ref: "#/components/schemas/ClientLocation"
                  paging:
                    $ref: "#/components/schemas/PagingInfo"
        "400":
          $ref: "#/components/responses/BadRequest"
        "401":
          $ref: "#/components/responses/Unauthorized"
        "403":
          $ref: "#/components/responses/Forbidden"
        "500":
          $ref: "#/components/responses/InternalServerError"
    post:
      tags:
        - Client Location
      summary: Create a new client location
      description: Create a new client location entry
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/CreateClientLocationRequest"
      responses:
        "201":
          description: Client location created successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    $ref: "#/components/schemas/ClientLocation"
        "400":
          $ref: "#/components/responses/BadRequest"
        "401":
          $ref: "#/components/responses/Unauthorized"
        "403":
          $ref: "#/components/responses/Forbidden"
        "422":
          $ref: "#/components/responses/ValidationError"
        "500":
          $ref: "#/components/responses/InternalServerError"
  /client-location/{id}:
    get:
      tags:
        - Client Location
      summary: Get client location by ID
      description: Retrieve a specific client location by its ID
      parameters:
        - name: id
          in: path
          required: true
          description: Client location ID
          schema:
            type: string
      responses:
        "200":
          description: Successful response
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    $ref: "#/components/schemas/ClientLocation"
        "400":
          $ref: "#/components/responses/BadRequest"
        "401":
          $ref: "#/components/responses/Unauthorized"
        "403":
          $ref: "#/components/responses/Forbidden"
        "404":
          $ref: "#/components/responses/NotFound"
        "500":
          $ref: "#/components/responses/InternalServerError"
    patch:
      tags:
        - Client Location
      summary: Update client location
      description: Update an existing client location
      parameters:
        - name: id
          in: path
          required: true
          description: Client location ID
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/UpdateClientLocationRequest"
      responses:
        "200":
          description: Client location updated successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    $ref: "#/components/schemas/ClientLocation"
        "400":
          $ref: "#/components/responses/BadRequest"
        "401":
          $ref: "#/components/responses/Unauthorized"
        "403":
          $ref: "#/components/responses/Forbidden"
        "404":
          $ref: "#/components/responses/NotFound"
        "422":
          $ref: "#/components/responses/ValidationError"
        "500":
          $ref: "#/components/responses/InternalServerError"
    delete:
      tags:
        - Client Location
      summary: Delete client location
      description: Delete a client location by ID
      parameters:
        - name: id
          in: path
          required: true
          description: Client location ID
          schema:
            type: string
      responses:
        "200":
          description: Client location deleted successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
        "400":
          $ref: "#/components/responses/BadRequest"
        "401":
          $ref: "#/components/responses/Unauthorized"
        "403":
          $ref: "#/components/responses/Forbidden"
        "404":
          $ref: "#/components/responses/NotFound"
        "500":
          $ref: "#/components/responses/InternalServerError"
  /client-location/remove:
    post:
      tags:
        - Client Location
      summary: Bulk delete client locations
      description: Delete multiple client locations by their IDs
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                ids:
                  type: array
                  items:
                    type: string
                  description: Array of client location IDs to delete
              required:
                - ids
      responses:
        "200":
          description: Client locations deleted successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
        "400":
          $ref: "#/components/responses/BadRequest"
        "401":
          $ref: "#/components/responses/Unauthorized"
        "403":
          $ref: "#/components/responses/Forbidden"
        "500":
          $ref: "#/components/responses/InternalServerError"
components:
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: Authorization
      description: "Use format: Bearer {api_key}"
  schemas:
    ClientLocation:
      type: object
      properties:
        _id:
          type: string
          description: Unique identifier
          example: "507f1f77bcf86cd799439011"
        client:
          type: string
          description: Client ID
          example: "507f1f77bcf86cd799439012"
        name:
          type: string
          description: Location name
          example: "Main Office"
        address:
          type: string
          description: Street address
          example: "123 Main St"
        city:
          type: string
          description: City name
          example: "New York"
        state:
          type: string
          description: State or province
          example: "NY"
        postal_code:
          type: string
          description: Postal or ZIP code
          example: "10001"
        country:
          type: string
          description: Country name
          example: "United States"
        coordinates:
          type: object
          properties:
            latitude:
              type: number
              format: float
              description: Latitude coordinate
              example: 40.7128
            longitude:
              type: number
              format: float
              description: Longitude coordinate
              example: -74.0060
        is_primary:
          type: boolean
          description: Whether this is the primary location
          example: true
        location_type:
          type: string
          description: Type of location
          enum: ["office", "warehouse", "retail", "branch", "other"]
          example: "office"
        contact_info:
          type: object
          properties:
            phone:
              type: string
              description: Phone number
              example: "+1-555-123-4567"
            email:
              type: string
              format: email
              description: Email address
              example: "contact@example.com"
            fax:
              type: string
              description: Fax number
        business_hours:
          type: object
          properties:
            monday:
              $ref: "#/components/schemas/BusinessHours"
            tuesday:
              $ref: "#/components/schemas/BusinessHours"
            wednesday:
              $ref: "#/components/schemas/BusinessHours"
            thursday:
              $ref: "#/components/schemas/BusinessHours"
            friday:
              $ref: "#/components/schemas/BusinessHours"
            saturday:
              $ref: "#/components/schemas/BusinessHours"
            sunday:
              $ref: "#/components/schemas/BusinessHours"
        notes:
          type: string
          description: Additional notes about the location
        company_namespace:
          type: array
          items:
            type: string
          description: Company namespace
        disabled:
          type: boolean
          description: Whether the location is disabled
          example: false
        createdAt:
          type: string
          format: date-time
          description: Creation timestamp
        modifiedAt:
          type: string
          format: date-time
          description: Last modification timestamp
        SVClient:
          type: integer
          description: Client version
        __v:
          type: integer
          description: Document version
      required:
        - client
        - name
        - address
    BusinessHours:
      type: object
      properties:
        open:
          type: string
          format: time
          description: Opening time (HH:MM format)
          example: "09:00"
        close:
          type: string
          format: time
          description: Closing time (HH:MM format)
          example: "17:00"
        is_closed:
          type: boolean
          description: Whether the location is closed on this day
          default: false
    CreateClientLocationRequest:
      type: object
      properties:
        client:
          type: string
          description: Client ID
          example: "507f1f77bcf86cd799439012"
        name:
          type: string
          description: Location name
          example: "Main Office"
        address:
          type: string
          description: Street address
          example: "123 Main St"
        city:
          type: string
          description: City name
          example: "New York"
        state:
          type: string
          description: State or province
          example: "NY"
        postal_code:
          type: string
          description: Postal or ZIP code
          example: "10001"
        country:
          type: string
          description: Country name
          example: "United States"
        coordinates:
          type: object
          properties:
            latitude:
              type: number
              format: float
            longitude:
              type: number
              format: float
        is_primary:
          type: boolean
          description: Whether this is the primary location
          default: false
        location_type:
          type: string
          description: Type of location
          enum: ["office", "warehouse", "retail", "branch", "other"]
          default: "office"
        contact_info:
          type: object
          properties:
            phone:
              type: string
            email:
              type: string
              format: email
            fax:
              type: string
        business_hours:
          type: object
          properties:
            monday:
              $ref: "#/components/schemas/BusinessHours"
            tuesday:
              $ref: "#/components/schemas/BusinessHours"
            wednesday:
              $ref: "#/components/schemas/BusinessHours"
            thursday:
              $ref: "#/components/schemas/BusinessHours"
            friday:
              $ref: "#/components/schemas/BusinessHours"
            saturday:
              $ref: "#/components/schemas/BusinessHours"
            sunday:
              $ref: "#/components/schemas/BusinessHours"
        notes:
          type: string
          description: Additional notes about the location
        company_namespace:
          type: array
          items:
            type: string
          description: Company namespace
        disabled:
          type: boolean
          description: Whether the location is disabled
          default: false
      required:
        - client
        - name
        - address
    UpdateClientLocationRequest:
      type: object
      properties:
        name:
          type: string
          description: Location name
        address:
          type: string
          description: Street address
        city:
          type: string
          description: City name
        state:
          type: string
          description: State or province
        postal_code:
          type: string
          description: Postal or ZIP code
        country:
          type: string
          description: Country name
        coordinates:
          type: object
          properties:
            latitude:
              type: number
              format: float
            longitude:
              type: number
              format: float
        is_primary:
          type: boolean
          description: Whether this is the primary location
        location_type:
          type: string
          description: Type of location
          enum: ["office", "warehouse", "retail", "branch", "other"]
        contact_info:
          type: object
          properties:
            phone:
              type: string
            email:
              type: string
              format: email
            fax:
              type: string
        business_hours:
          type: object
          properties:
            monday:
              $ref: "#/components/schemas/BusinessHours"
            tuesday:
              $ref: "#/components/schemas/BusinessHours"
            wednesday:
              $ref: "#/components/schemas/BusinessHours"
            thursday:
              $ref: "#/components/schemas/BusinessHours"
            friday:
              $ref: "#/components/schemas/BusinessHours"
            saturday:
              $ref: "#/components/schemas/BusinessHours"
            sunday:
              $ref: "#/components/schemas/BusinessHours"
        notes:
          type: string
          description: Additional notes about the location
        company_namespace:
          type: array
          items:
            type: string
          description: Company namespace
        disabled:
          type: boolean
          description: Whether the location is disabled
    PagingInfo:
      type: object
      properties:
        total:
          type: integer
          description: Total number of items
        page:
          type: integer
          description: Current page number
        per_page:
          type: integer
          description: Items per page
        pages:
          type: integer
          description: Total number of pages
  responses:
    BadRequest:
      description: Bad request
      content:
        application/json:
          schema:
            type: object
            properties:
              success:
                type: boolean
                example: false
              error:
                type: string
                example: "Invalid request parameters"
    Unauthorized:
      description: Unauthorized
      content:
        application/json:
          schema:
            type: object
            properties:
              success:
                type: boolean
                example: false
              error:
                type: string
                example: "Authentication required"
    Forbidden:
      description: Forbidden
      content:
        application/json:
          schema:
            type: object
            properties:
              success:
                type: boolean
                example: false
              error:
                type: string
                example: "Insufficient permissions"
    NotFound:
      description: Resource not found
      content:
        application/json:
          schema:
            type: object
            properties:
              success:
                type: boolean
                example: false
              error:
                type: string
                example: "Resource not found"
    ValidationError:
      description: Validation error
      content:
        application/json:
          schema:
            type: object
            properties:
              success:
                type: boolean
                example: false
              error:
                type: string
                example: "Validation failed"
    InternalServerError:
      description: Internal server error
      content:
        application/json:
          schema:
            type: object
            properties:
              success:
                type: boolean
                example: false
              error:
                type: string
                example: "Internal server error"
