openapi: 3.0.0
info:
  title: Widgetized Homepage API
  version: 1.0.0
  description: API for managing templates and widgets for a widgetized homepage and sub-pages.

# servers:
#   - url: http://localhost:3000
#     description: Local server

paths:
  /template/template/{page}:
    get:
      tags:
        - "Template"
      summary: Get template details of a particular page
      parameters:
        - in: path
          name: page
          required: true
          schema:
            type: string
          description: The page for which template details are requested.
        - in: query # Add platform as a query parameter
          name: platform
          required: true
          schema:
            type: string
            enum: ['web', 'mobile', 'both']
          description: The platform for which template details are requested (web, mobile, or both).
      responses:
        '200':
          description: Template retrieved successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                  name:
                    type: string
                  desc:
                    type: string
                  widgets:
                    type: array
                    items:
                      type: object
                        position:
                          type: integer
                        startTime:
                          type: string
                          format: date-time
                        endTime:
                          type: string
                          format: date-time
                  hashId:
                    type: string
        '404':
          description: Template not found
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string

  /widget/allWidget/{page}:
    get:
      tags:
        - "Widget"
      summary: Get widget details for a page
      parameters:
        - in: path
          name: page
          required: true
          schema:
            type: string
          description: The page for which widget details are requested.
      responses:
        '200':
          description: Widgets retrieved successfully
          content:
            application/json:
              schema:
                type: array
                items:
                  type: object
                  properties:
                    id:
                      type: string
                    title:
                      type: string
                    widget:
                      type: string
                    enable:
                      type: boolean
                    buttonData:
                      type: array
                      items:
                        type: object
                        properties:
                          url:
                            type: string
                          title:
                            type: string
                    sectionHeadingText:
                      type: string
                    apiUrl:
                      type: string
                    list:
                      type: array
                      items:
                        type: object
                        properties:
                          bannerData:
                            type: object
                            properties:
                              imageName:
                                type: string
                              headingText:
                                type: string
                              subHeadingText:
                                type: string
                              landingUrl:
                                type: string
                              timerPosition:
                                type: string
                              timerColor:
                                type: string
                          dimension:
                            type: object
                            properties:
                              length:
                                type: integer
                              breadth:
                                type: integer
                          banner_title:
                            type: string
        '404':
          description: Widgets not found
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string

  /widget/createWidget:
    post:
      tags:
        - "Widget"
      summary: Create a new widget
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                title:
                  type: string
                widget:
                  type: string
                enable:
                  type: boolean
                buttonData:
                  type: array
                  items:
                    type: object
                    properties:
                      url:
                        type: string
                      title:
                        type: string
                sectionHeadingText:
                  type: string
                apiUrl:
                  type: string
                list:
                  type: array
                  items:
                    type: object
                    properties:
                      bannerData:
                        type: object
                        properties:
                          imageName:
                            type: string
                          headingText:
                            type: string
                          subHeadingText:
                            type: string
                          landingUrl:
                            type: string
                          timerPosition:
                            type: string
                          timerColor:
                            type: string
                      dimension:
                        type: object
                        properties:
                          length:
                            type: integer
                          breadth:
                            type: integer
                      banner_title:
                        type: string
      responses:
        '201':
          description: Widget created successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                  message:
                    type: string
        '400':
          description: Bad request
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string

  /template/{page}/widgets/{widgetId}/{templateId}:
    put:
      tags:
        - "Template"
      summary: Update and map a widget to a particular page
      parameters:
        - in: path
          name: page
          required: true
          schema:
            type: string
          description: The page to which the widget is to be mapped.
        - in: path
          name: widgetId
          required: true
          schema:
            type: string
          description: The widget ID that needs to be mapped.
        - in: path
          name: templateId
          required: true
          schema:
            type: string
          description: The template ID that needs to be mapped.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                position:
                  type: integer
                startTime:
                  type: string
                  format: date-time
                endTime:
                  type: string
                  format: date-time
      responses:
        '200':
          description: Widget mapped successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                  widgetId:
                    type: string
                  page:
                    type: string
                  position:
                    type: integer
        '400':
          description: Bad request
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string

  /template/createTemplate:
    post:
      tags:
        - "Template"
      summary: Create a new template
      description: Create a new template for a specific page, including widget mapping and scheduling.
      requestBody:
        description: The template to create
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
                  description: The name of the template
                  example: "Homepage Template"
                desc:
                  type: string
                  description: A description of the template
                  example: "Template for the homepage widget"
                platform:
                  type: string
                  enum: ['web', 'mobile', 'both']
                  description: The platform for which the template is intended
                  example: "web"
                widgets:
                  type: array
                  description: A list of widgets mapped to the template
                  items:
                    type: object
                    properties:
                      widgetId:
                        type: string
                        description: The ID of the widget
                        example: "64e9b0d4f3a1a85e5e4e9f76"
                      position:
                        type: integer
                        description: The position of the widget in the template
                        example: 0
                      startTime:
                        type: string
                        format: date-time
                        description: The start time for the widget to be active
                        example: "2024-01-01T00:00:00Z"
                      endTime:
                        type: string
                        format: date-time
                        description: The end time for the widget to be active
                        example: "2024-12-31T23:59:59Z"
                hashId:
                  type: string
                  description: A unique identifier for the template
                  example: "homepage-template-001"
      responses:
        '201':
          description: Template created successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                    example: "Template created successfully"
                  id:
                    type: string
                    description: The ID of the created template
                    example: "64e9b0d4f3a1a85e5e4e9f78"
        '400':
          description: Bad request
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    example: "Validation error: 'name' is required."