import { merge } from 'lodash';

import fullSchema from 'vets-json-schema/dist/21-526EZ-ALLCLAIMS-schema.json';
import AuthorityField from '../components/AuthorityField';
import { ptsd781aNameTitle } from '../content/ptsdClassification';
import { PtsdAssaultAuthoritiesDescription } from '../content/ptsdAssaultAuthorities';
import { uiSchema as addressUI } from '../../../../platform/forms/definitions/address';
import { validateZIP } from '../validations';

const { sources } = fullSchema.definitions.secondaryPtsdIncident.properties;

export const uiSchema = index => ({
  'ui:title': ptsd781aNameTitle,
  'ui:description': PtsdAssaultAuthoritiesDescription,
  [`secondaryIncident${index}`]: {
    sources: {
      'ui:options': {
        itemName: 'Authority',
        viewField: AuthorityField,
      },
      items: {
        name: {
          'ui:title': 'Name of official or authority',
        },
        address: merge(addressUI(''), {
          'ui:order': [
            'country',
            'addressLine1',
            'addressLine2',
            'city',
            'state',
            'zipCode',
          ],
          addressLine1: {
            'ui:title': 'Street',
          },
          addressLine2: {
            'ui:title': 'Street 2',
          },
          zipCode: {
            'ui:title': 'Postal Code',
            'ui:validations': [validateZIP],
          },
        }),
      },
    },
  },
});

export const schema = index => ({
  type: 'object',
  properties: {
    [`secondaryIncident${index}`]: {
      type: 'object',
      properties: {
        sources,
      },
    },
  },
});

@@ -1372,16 +1372,171 @@
 teZIP%5D,%0A
+            'ui:errorMessages': %7B%0A              pattern:%0A                'Please enter a valid 5- or 9-digit Postal code (dashes allowed)',%0A            %7D,%0A
         

fix postal code error message (#9377)