openapi: "3.0.0"
info:
  version: 0.0.1
  title: Lueira BackOffice REST API
  description: BackOffice API for lueira
  contact:
    name: Maladeta Studio
    url: http://www.maladetastudio.com
    email: tech@maladetastudio.com
servers:
  - url: https://api.lueira.com/backoffice
  - url: https://api.pre.lueira.com/backoffice
  - url: http://localhost:8000/backoffice
security:
  - BearerAuth: []
tags:
  - name: Auth
    description: Authentication

paths:
  /auth/login:
    post:
      summary: Login a user of backoffice
      operationId: AuthLogin
      security:
        - {}
      tags:
        - Auth
      requestBody:
        description: Request id and code
        content:
          "application/json":
            schema:
              type: object
              properties:
                username:
                  type: string
                  example: username
                password:
                  type: string
                  example: "123456"
      responses:
        "200":
          description: Auth token for a user
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/BackOfficeUserAuthToken"

  /tenants:
    get:
      summary: Get all the tenants
      operationId: GetTenants
      security:
        - BearerAuth: []
      tags:
        - Tenant
      parameters:
        - in: query
          name: q
          schema:
            type: string
          description: text to search for
          example: ant
      responses:
        "200":
          description: All tenants
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: "#/components/schemas/Tenant"
    post:
      summary: Create a tenant
      operationId: TenantCreate
      tags:
        - Tenant
      requestBody:
        description: Create a new tenant
        content:
          "application/json":
            schema:
              $ref: "#/components/schemas/TenantCreateRequest"
      responses:
        "200":
          description: Creation of a tenant
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Tenant"
  /tenants/{tenant_id}:
    get:
      summary: Get a specific tenant
      operationId: GetTenant
      security:
        - BearerAuth: []
      tags:
        - Tenant
      parameters:
        - in: path
          name: tenant_id
          schema:
            type: string
          required: true
          description: Id of the tenant
          example: tenantid
      responses:
        "200":
          description: Tenant with tenantid
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Tenant"
    patch:
      summary: Update tenant
      operationId: TenantUpdate
      tags:
        - Tenant
      parameters:
        - in: path
          name: tenant_id
          schema:
            type: string
          required: true
          description: Id of the tenant
          example: tenantid
      requestBody:
        description: Update a tenant
        content:
          "application/json":
            schema:
              $ref: "#/components/schemas/TenantUpdateRequest"
      responses:
        "200":
          description: Tenant info
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Tenant"
    delete:
      summary: Delete a tenant
      operationId: TenantDelete
      tags:
        - Tenant
      parameters:
        - in: path
          name: tenant_id
          schema:
            type: string
          required: true
          description: Id of the tenant
          example: tenantid
      responses:
        "204":
          description: And it is gone
  /tenants/{tenant_id}/users:
    get:
      summary: List of users of a tenant
      operationId: TenantUsersList
      tags:
        - Tenant
      parameters:
        - in: path
          name: tenant_id
          schema:
            type: string
          required: true
          description: Id of the tenant
          example: tenantid
      responses:
        "200":
          description: List of users of a tenant
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: "#/components/schemas/User"
    post:
      summary: Create a user
      operationId: TenantUserCreate
      tags:
        - Tenant
      deprecated: true
      parameters:
        - in: path
          name: tenant_id
          schema:
            type: string
          required: true
          description: Id of the tenant
          example: tenantid
      requestBody:
        description: Create a new user
        content:
          "application/json":
            schema:
              $ref: "#/components/schemas/UserCreateRequest"
      responses:
        "200":
          description: Creation of a user
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/User"
  /users:
    get:
      summary: List of all users
      operationId: UsersList
      parameters:
        - in: query
          name: q
          schema:
            type: string
          description: text to search for
          example: ant
      tags:
        - User
      responses:
        "200":
          description: AuthToken
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: "#/components/schemas/User"
    post:
      summary: Create a user
      operationId: UserCreate
      tags:
        - User
      requestBody:
        description: Create a new user
        content:
          "application/json":
            schema:
              $ref: "#/components/schemas/UserCreateRequest"
      responses:
        "200":
          description: Creation of a user
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/User"
  /users/{user_id}:
    get:
      summary: Details of a user
      operationId: User Details
      tags:
        - User
      parameters:
        - in: path
          name: user_id
          schema:
            type: string
          required: true
          description: Id of the user
          example: userid
      responses:
        "200":
          description: User details
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/User"
    patch:
      summary: Update user
      operationId: UserUpdate
      tags:
        - User
      parameters:
        - in: path
          name: user_id
          schema:
            type: string
          required: true
          description: Id of the user
          example: userid
      requestBody:
        description: Update a user
        content:
          "application/json":
            schema:
              $ref: "#/components/schemas/UserUpdateRequest"
      responses:
        "200":
          description: User updated
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/User"
    delete:
      summary: Delete a user
      operationId: UserDelete
      tags:
        - User
      parameters:
        - in: path
          name: user_id
          schema:
            type: string
          required: true
          description: Id of the user
          example: userid
      responses:
        "204":
          description: And it is gone
  /users/{user_id}/impersonate:
    post:
      summary: Impersonate a user
      operationId: UserImpersonate
      tags:
        - User
      parameters:
        - in: path
          name: user_id
          schema:
            type: string
          required: true
          description: Id of the user
          example: userid
      responses:
        "200":
          description: User details
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/User"
  /me:
    get:
      summary: Details of a backoffice user
      operationId: UserDetails
      tags:
        - BackOfficeUser
      responses:
        "200":
          description: User details
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/BackOfficeUser"
  /create-demo:
    post:
      summary: Create a demo
      operationId: createDemo
      security:
        - {}
      tags:
        - Demo
      requestBody:
        description: Create a demo
        content:
          "application/json":
            schema:
              $ref: "#/components/schemas/DemoCreateRequest"
      responses:
        "200":
          description: Demo created
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                    example: "created demo"
  /send-notification:
    post:
      summary: Send a notification
      operationId: sendNotification
      security:
        - {}
      tags:
        - Notifications
      requestBody:
        description: Send a notification
        content:
          "application/json":
            schema:
              $ref: "#/components/schemas/SendNotificationRequest"
      responses:
        "200":
          description: Demo created
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                    example: "notification sent"

components:
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
  schemas:
    DateTime:
      type: string
      example: "2022-07-06T19:43:42Z"
    BackOfficeUserAuthToken:
      type: object
      properties:
        token:
          type: string
          example: asuperlongrandomtokenl
    BackOfficeUser:
      type: object
      properties:
        id:
          type: string
          example: "123"
        user:
          type: string
          example: "user1"
        first_name:
          type: string
          example: "John"
        last_name:
          type: string
          example: "Doe"
        email:
          type: string
          example: "john.doe@example.com"
        password:
          type: string
          example: "password123"
        is_deleted:
          type: boolean
          example: false
        created_at:
          $ref: "#/components/schemas/DateTime"
        tenant:
          $ref: "#/components/schemas/Tenant"
    Tenant:
      type: object
      properties:
        id:
          type: string
          example: "tenantid"
        name:
          type: string
          example: "Simpson Ski School"
        vat_number:
          type: string
          example: "ES12345678Z"
        phone:
          type: string
          example: "+34123456789"
        email:
          type: string
          example: "tenant@example.com"
        address:
          type: string
          example: "123 Main St, Springfield"
        website_url:
          type: string
          example: "https://www.simpsonskischool.com"
        slug:
          type: string
          example: "simpson-ski-school"
        is_store_enabled:
          type: boolean
          example: true
        is_shop_module_enabled:
          type: boolean
          example: true
        is_rent_module_enabled:
          type: boolean
          example: true
        is_school_module_enabled:
          type: boolean
          example: true
        is_trackr_module_enabled:
          type: boolean
          example: false          
        are_stripe_payments_active:
          type: boolean
          example: true
        school_opens_at:
          type: string
          example: "07:00"
        school_closes_at:
          type: string
          example: "20:00"
        timezone:
          type: string
          example: "Europe/Madrid"
          description: Timezone is stored in the IANA Time Zone format, e.g., "Europe/Madrid"
        default_language:
          type: string
          example: es
        currency:
          type: string
          example: "EUR"
          description: Currency is stored in ISO 4217 format
        instructor_extra_required_wage:
          $ref: "#/components/schemas/Amount"
        activity_type:
          type: string
          enum:
            - SKI
            - OTHERS
          example: SKI
        is_deleted:
          type: boolean
          example: false
    TenantUpdateRequest:
      type: object
      properties:
        name:
          type: string
          example: Simpson Ski School
        phone:
          type: string
          example: 600123123
        email:
          type: string
          example: hey@simpsonsskischool.com
        legal_name:
          type: string
          example: Simpsons Ski School S.L.
        vat_number:
          type: string
          example: ES-123
        website_url:
          type: string
          example: https://maladeta.studio
        address:
          type: string
          example: New square 8
        address_extra:
          type: string
          example: Modul 3
        postal_code:
          type: string
          example: 25530
        city:
          type: string
          example: Casau
        country_code:
          type: string
          example: es
        has_accepted_terms:
          type: boolean
          example: true
        logo_id:
          type: string
          example: logoid
        cover_image_id:
          type: string
          example: coverimageid
        school_opens_at:
          type: string
          example: 13:00
        school_closes_at:
          type: string
          example: 13:00
        rental_opens_at:
          type: string
          example: 13:00
        rental_closes_at:
          type: string
          example: 13:00
        is_store_enabled:
          type: boolean
          example: true
        is_trackr_module_enabled:
          type: boolean
          example: false          
        slug:
          type: string
          example: blue-ski
        privacy_policy:
          type: string
          example: theprivacy
        instructors_planning_view_threshold_hours:
          type: integer
          example: 3
        instructor_extra_required_wage_number:
          type: integer
          example: 4200
        instructor_extra_required_wage_currency:
          type: string
          example: "EUR"
        activity_type:
          type: string
          enum:
            - SKI
            - OTHERS
          example: SKI
    User:
      type: object
      properties:
        id:
          type: string
          example: userid
        first_name:
          type: string
          example: Marge
        last_name:
          type: string
          example: Simpson
        phone:
          type: string
          example: "973640000"
        email:
          type: string
          example: marge@simpsonsskischool.com
        created_at:
          $ref: "#/components/schemas/DateTime"
        is_deleted:
          type: boolean
          example: false
        language_code:
          type: string
          example: esp
          description: https://en.wikipedia.org/wiki/List_of_ISO_639-2_codes
        role:
          type: string
          example: "ADMIN"
          enum:
            - ADMIN
            - POS
    UserCreateRequest:
      type: object
      properties:
        first_name:
          type: string
          example: "John"
        last_name:
          type: string
          example: "Doe"
        email:
          type: string
          example: "john.doe@example.com"
        phone:
          type: string
          example: "+34123456789"
        password:
          type: string
          example: "password123"
        language_code:
          type: string
          example: "es"
        role:
          type: string
          example: "ADMIN"
          enum:
            - ADMIN
            - POS
        tenant_id:
          type: string
          example: "tenantid"
    TenantCreateRequest:
      type: object
      properties:
        name:
          type: string
          example: "Escuela Ejemplo"
        vat_number:
          type: string
          example: "ES12345678Z"
        email:
          type: string
          example: "escuela.ejemplo@example.com"
        phone:
          type: string
          example: "+34123456789"
        school_opens_at:
          type: string
          example: "08:00"
        school_closes_at:
          type: string
          example: "18:00"
        rental_opens_at:
          type: string
          example: "09:00"
        rental_closes_at:
          type: string
          example: "17:00"
        slug:
          type: string
          example: "escuela-ejemplo"
        is_store_enabled:
          type: boolean
          example: true
        is_trackr_module_enabled:
          type: boolean
          example: false          
        privacy_policy:
          type: string
          example: "Política de privacidad..."
        return_policy:
          type: string
          example: "Política de devoluciones..."
        is_shop_module_enabled:
          type: boolean
          example: true
        is_rent_module_enabled:
          type: boolean
          example: true
        is_school_module_enabled:
          type: boolean
          example: true
        instructors_planning_view_threshold_hours:
          type: integer
          example: 48
        default_language:
          type: string
          example: es
        currency:
          type: string
          example: "EUR"
          description: Currency is stored in ISO 4217 format
        timezone:
          type: string
          example: "Europe/Madrid"
          description: Timezone is stored in the IANA Time Zone format, e.g., "Europe/Madrid"
    UserAuthToken:
      type: object
      properties:
        token:
          type: string
          example: asuperlongrandomtokenl
    UserUpdateRequest:
      type: object
      properties:
        first_name:
          type: string
          example: "John"
        last_name:
          type: string
          example: "Doe"
        email:
          type: string
          example: "john.doe@example.com"
        phone:
          type: string
          example: "+34123456789"
        password:
          type: string
          example: "password123"
        is_deleted:
          type: boolean
          example: false
        language_code:
          type: string
          example: "es"
        tenant_id:
          type: string
          example: tenantid
        role:
          type: string
          example: "ADMIN"
          enum:
            - ADMIN
            - POS
        is_active:
          type: boolean
          example: true
    DemoCreateRequest:
      type: object
      properties:
        first_name:
          type: string
          example: "Nombre"
        last_name:
          type: string
          example: "lastname"
        email:
          type: string
          example: "usuario@ejemplo.com"
        password:
          type: string
          example: "password"
        tenant_name:
          type: string
          example: "tenant name"
        start_of_time:
          type: string
          format: date-time
          example: "2023-12-05T09:02:34Z"
        timezone:
          type: string
          example: "Europe/Madrid"
        is_shop_enabled:
          type: boolean
          example: true
        is_school_enabled:
          type: boolean
          example: true
        is_rent_enabled:
          type: boolean
          example: true
        file_path:
          type: string
          example: "/path/to/fixtures/demo-ski.hcl"
    SendNotificationRequest:
      type: object
      properties:
        title:
          type: string
          example: "title"
        text:
          type: string
          example: "text"
        image_url:
          type: string
          example: "image_url"
        actions:
          type: array
          items:
            type: string
            example: action
        deep_link:
          type: string
          example: "tenant name"
        instructor_ids:
          type: array
          items:
            type: string
            example: instructorid
    Amount:
      type: object
      properties:
        number:
          type: integer
          example: 5000
        currency_code:
          type: string
          example: EUR
