# it is important to use this apiVersion
apiVersion: witboost.com/v1
kind: EditTemplate
metadata:
  name: edit-base-streamlined-experience-template.1
  title: Minimal Information Output Port Edit Template
  description: Edit a basic Output Port
  tags:
    - edit
    - output-port
spec:
  owner: agilelab
  useCaseTemplateId:
    - urn:dmb:utm:base-streamlined-experience-template:0.0.0
  parameters:
    - title: Update Output Port
      description: |
        This wizard will allow you to edit the metadata for a previously created Output Port.
        
        Most metadata is editable but some (like the name, domain, data product etc) are not; their fields will be read-only.
        
        Some of the files in the component's repository cannot be updated by this wizard, namely:
        - **Documentation**: `README.md`, `docs/index.md`, etc
        - **CI/CD**: `.gitlab-ci-yaml`
        You need to take care of updating these yourself, as given their nature it's hard to do automatically and they are often edited manually after the component's creation.

    - title: Update component metadata
      description: Update basic information for this component
      required:
        - description
      properties:
        name:
          title: Name
          type: string
          description: Not editable. The name of the component.
          ui:disabled: true
        description:
          title: Description
          type: string
          description: Required. Help others understand what this component is for. What data will it expose?
        domain:
          title: Domain
          type: string
          description: Not editable. Domain of the Data Product this component belongs to
          ui:field: EntityPicker
          ui:options:
            allowArbitraryValues: false
            allowedKinds:
              - Domain
          ui:disabled: true
        dataproduct:
          title: Data Product
          type: string
          description: Not editable. Data Product this component belongs to
          ui:field: EntityPicker
          ui:filter:
            - fieldName: domain
              entityPath: spec.domain
          ui:options:
            allowArbitraryValues: false
            allowedKinds:
              - System
          ui:disabled: true
        identifier:
          title: Identifier
          type: string
          description: Autogenerated from the information above. A unique identifier for the component. It will not be editable after creation and is a string composed of [a-zA-Z] separated by any of [-_].
          ui:field: ComponentIdentifierPicker
          ui:options:
            allowArbitraryValues: false
        developmentGroup:
          title: Development Group
          type: string
          description: Automatically selected from the Data Product metadata. Data Product development group.
          ui:field: EntitySelectionPicker
          ui:fieldName: dataproduct
          ui:property: spec.owner
          ui:options:
            allowArbitraryValues: false
        dependsOn:
          title: Dependencies
          type: array
          description: A component could depend on other components in the same Data Product. This information will be used to deploy the components in such an order that their dependencies already exist.
          default: [ ]
          items:
            type: string
            ui:field: EntityRelationsPicker
            ui:fieldName: dataproduct
            relation: hasPart
        tags:
          title: Tags
          type: array
          description: Tags for the component
          default: []
          items:
            type: string

    - title: Update Terms & Conditions and SLA
      description: Update Terms & Conditions and Service Level Agreement information for this Data product.
      required:
        - termsAndConditions
        - intervalOfChange
        - timeliness
        - upTime
      properties:
        termsAndConditions:
          title: Terms and Conditions
          type: string
          description: Required. Terms and Conditions that apply to the data.
          default: Can be used for production purposes.
        intervalOfChange:
          title: Interval of change
          type: string
          description: Required. How often the data is refreshed.
          default: 2BD
        timeliness:
          title: Timeliness
          type: string
          description: Required. Timeliness of the data.
          default: 2BD
        upTime:
          title: Uptime
          type: string
          description: Required. Uptime of the Output Port.
          default: 99.9%

    - title: Update Data Sharing Agreement
      description: Update the Data Sharing Agreement clauses for this Data product.
      required:
        - purpose
        - billing
        - security
        - intendedUsage
        - limitations
        - lifeCycle
        - confidentiality
      properties:
        purpose:
          title: Purpose
          type: string
          description: Required. Purpose of the data.
          default: Foundational data for downstream sue cases.
        billing:
          title: Billing
          type: string
          description: Required. Billing applied to data usage.
          default: None.
        security:
          title: Security
          type: string
          description: Required. Security policies that apply to the data.
          default: Platform standard security policies.
        intendedUsage:
          title: Intended Usage
          type: string
          description: Required. Intended usage for the data.
          default: Any downstream use cases.
        limitations:
          title: Limitations
          type: string
          description: Required. Limitations of the data.
          default: Needs joining with other datasets (eg customer data) for most analytical use cases.
        lifeCycle:
          title: Lifecycle
          type: string
          description: Required. Lifecycle of the data.
          default: Data loaded every two days and typically never deleted.
        confidentiality:
          title: Confidentiality
          type: string
          description: Required. Confidentiality of the data.
          default: None.

    - title: Data contract schema
      description: Definition of the columns of the table. Primitive data types supported.
      properties:
        schemaDefinition:
          type: object
          ui:options:
            displayTitle: false
          properties:
            schemaColumns:
              title: Column Definitions
              type: array
              ui:ArrayFieldTemplate: ArrayTableTemplate
              items:
                type: object
                ui:ObjectFieldTemplate: TableRowTemplate
                required:
                  - name
                  - dataType
                properties:
                  name:
                    type: string
                    title: Name
                  description:
                    type: string
                    title: Description
                  dataType:
                    type: string
                    default: INT
                    title: Data Type
                    enum:
                      - TINYINT
                      - SMALLINT
                      - INT
                      - BIGINT
                      - DOUBLE
                      - DECIMAL
                      - TIMESTAMP
                      - DATE
                      - STRING
                      - TEXT
                      - CHAR
                      - VARCHAR
                      - BOOLEAN
                      - ARRAY
                  constraint:
                    type: string
                    title: Constraint
                    default: (no constraint)
                    enum:
                      - PRIMARY_KEY
                      - NOT_NULL
                      - UNIQUE
                      - (no constraint)
                allOf:
                  - if:
                      properties:
                        dataType:
                          const: ARRAY
                    then:
                      required:
                        - arrayDataType
                      properties:
                        arrayDataType:
                          title: Array Data Type
                          description: Data type of the array elements
                          type: string
                          default: INT
                          enum:
                            - TINYINT
                            - SMALLINT
                            - INT
                            - BIGINT
                            - DOUBLE
                            - DECIMAL
                            - TIMESTAMP
                            - DATE
                            - STRING
                            - TEXT
                            - CHAR
                            - VARCHAR
                            - BOOLEAN
                            - ARRAY
                      allOf:
                        - if:
                            properties:
                              arrayDataType:
                                oneOf:
                                  - const: TEXT
                                  - const: VARCHAR
                                  - const: CHAR
                          then:
                            properties:
                              dataLength:
                                title: Column Length
                                type: integer
                                description: Maximum length of column row
                                default: 65535
                            required:
                              - dataLength
                        - if:
                            properties:
                              arrayDataType:
                                oneOf:
                                  - const: DECIMAL
                          then:
                            properties:
                              precision:
                                title: Precision
                                type: integer
                                description: Precision of the numeric data type
                                minimum: 1
                                maximum: 38
                                default: 38
                              scale:
                                title: Scale
                                type: integer
                                description: Scale of the numeric data type; cannot be greater than precision minus 1
                                minimum: 0
                                maximum: 37
                                default: 0
                            required:
                              - precision
                              - scale
                  - if:
                      properties:
                        dataType:
                          oneOf:
                            - const: TEXT
                            - const: VARCHAR
                            - const: CHAR
                    then:
                      properties:
                        dataLength:
                          title: Column Length
                          type: integer
                          description: Maximum length of column row
                          default: 65535
                      required:
                        - dataLength
                  - if:
                      properties:
                        dataType:
                          oneOf:
                            - const: DECIMAL
                    then:
                      properties:
                        precision:
                          title: Precision
                          type: integer
                          description: Precision of the numeric data type
                          minimum: 1
                          maximum: 38
                          default: 38
                        scale:
                          title: Scale
                          type: integer
                          description: Scale of the numeric data type; cannot be greater than precision minus 1
                          minimum: 0
                          maximum: 37
                          default: 0
                      required:
                        - precision
                        - scale
                  - if: true
                    then:
                      properties:
                        businessTerms:
                          title: Business Terms
                          type: array
                          description: Multiple selection for fixed tags
                          uniqueItems: true
                          ui:style:
                            minWidth: 400
                          items:
                            type: string
                            enum:
                              - Raw
                              - Derived
                              - Metadata
                              - Identifier
                              - Dimension
                              - Fact

    - title: Provide Output port deployment information
      required:
        - databaseName
        - tableName
      properties:
        databaseName:
          title: Database name
          type: string
          description: Database name where the Output Port table will be created
        tableName:
          title: Table name
          type: string
          description: Table name created by this component to act as Output Port

  steps:
    - id: template
      name: Fetch Skeleton + Template
      action: fetch:template
      input:
        url: ./edit-skeleton
        targetPath: '.'
        values:
          name: '${{ parameters.name }}'
          description: '${{ parameters.description }}'
          domain: '${{ parameters.domain }}'
          dataproduct: '${{ parameters.dataproduct }}'
          identifier: '${{ parameters.identifier }}'
          developmentGroup: '${{ parameters.developmentGroup }}'
          dependsOn: '${{ parameters.dependsOn }}'
          tags: '${{ values.tags }}'
          processDescription: '${{ parameters.processDescription }}'
          intervalOfChange: '${{ parameters.intervalOfChange }}'
          timeliness: '${{ parameters.timeliness }}'
          upTime: '${{ parameters.upTime }}'
          termsAndConditions: '${{ parameters.termsAndConditions }}'
          endpoint: '${{ parameters.endpoint }}'
          schemaColumns: '${{ parameters.schemaDefinition.schemaColumns }}'
          purpose: '${{ parameters.purpose }}'
          billing: '${{ parameters.billing }}'
          security: '${{ parameters.security }}'
          intendedUsage: '${{ parameters.intendedUsage }}'
          limitations: '${{ parameters.limitations }}'
          lifeCycle: '${{ parameters.lifeCycle }}'
          confidentiality: '${{ parameters.confidentiality }}'
          databaseName: '${{ parameters.databaseName }}'
          tableName: '${{ parameters.tableName }}'
          creationDate: '${{ parameters.creationDate }}'
