import { TAB_GENERAL, TYPE_FACEBOOK, TYPE_YOUTUBE } from '../constants';

export const validationScheme = [
  {
    fieldName: 'platform',
    tabId: TAB_GENERAL,
    validation: (value, allProps) => {
      if (!allProps.accessToken) {
        return 'You must be autorized';
      }

      return '';
    },
  },
  {
    fieldName: 'name',
    tabId: TAB_GENERAL,
    validation: (value) => {
      if (!value) {
        return 'Field cannot be empty';
      }

      if (value.length > 250) {
        return 'The Name field can’t exceed 250 characters';
      }

      return '';
    },
  },
  {
    fieldName: 'publisherId',
    tabId: TAB_GENERAL,
    validation: (value) => {
      if (!value) {
        return 'Field cannot be empty';
      }

      return '';
    },
  },
  {
    fieldName: 'defaultChannel',
    tabId: TAB_GENERAL,
    validation: (value, allProps) => {
      if (!allProps.channels?.length) {
        let name = '';
        let channelName = '';

        if (allProps.type === TYPE_YOUTUBE) {
          name = 'Youtube';
          channelName = 'channel';
        } else if (allProps.type === TYPE_FACEBOOK) {
          name = 'Facebook';
          channelName = 'page';
        }

        return `The ${name} account must have a ${channelName}`;
      }

      if (!value) {
        return 'Please choose channel';
      }

      return '';
    },
  },
];
