import { TAB_GENERAL } from '../constants';

export const validationScheme = [
  {
    fieldName: 'account',
    tabId: TAB_GENERAL,
    validation: (value) => {
      if (!value) {
        return 'Field cannot be empty';
      }

      return '';
    },
  },
  {
    fieldName: 'publisherIds',
    tabId: TAB_GENERAL,
    validation: (value, currentState) => {
      if (!value.length && !currentState.allSites) {
        return 'Field cannot be empty';
      }

      return '';
    },
  },
  {
    fieldName: 'lookerReportId',
    tabId: TAB_GENERAL,
    validation: (title) => {
      const value = title?.trim();

      if (!value) {
        return 'Field cannot be empty';
      }
      if (value.length < 2) {
        return 'Field cannot be less then 2 symbols';
      }
      if (value.length > 50) {
        return 'Looker Dashboard ID is too long';
      }

      return '';
    },
  },
  {
    fieldName: 'uiName',
    tabId: TAB_GENERAL,
    validation: (title) => {
      const value = title?.trim();

      if (!value) {
        return 'Field cannot be empty';
      }
      if (value.length < 2) {
        return 'Field cannot be less then 2 symbols';
      }
      if (value.length > 50) {
        return 'Name is too long';
      }

      return '';
    },
  },
  {
    fieldName: 'description',
    tabId: TAB_GENERAL,
    validation: (description) => {
      const value = description?.trim();

      if (value.length > 50) {
        return 'Description is too long';
      }

      return '';
    },
  },
];
