import * as yup from 'yup'

const RSR = yup.object().shape({
  isPublic: yup.boolean().default(true),
  validations: yup.array().of(yup.number()).default([1, 2]),
  title: yup.string().default('').required().min(3),
  subtitle: yup.string().default('').required().min(3),
  iatiStatus: yup.string().required(),
  dateStartPlanned: yup.string().nullable().when('dateStartActual', {
    is: value => value === null || value === '' || value === undefined,
    then: yup.string().nullable().required()
  }),
  dateEndPlanned: yup.string().nullable(),
  dateStartActual: yup.string().nullable(),
  dateEndActual: yup.string().nullable(),
  currency: yup.string().default('EUR'),
  language: yup.string().default('en'),
  currentImage: yup.string().nullable().required(),
  currentImageCaption: yup.string(),
  currentImageCredit: yup.string(),
  defaultAidType: yup.string()
})

const EUTF = RSR.clone().shape({
  iatiActivityId: yup.string().nullable()
})

const IATI_BASIC = RSR.clone().shape({
  iatiActivityId: yup.string().nullable().required().min(1)
})

const IATI = IATI_BASIC.clone().shape({
  hierarchy: yup.string().nullable(),
  defaultAidTypeVocabulary: yup.string(),
  // defaultAidType: yup.string(),
  defaultFlowType: yup.string(),
  defaultTiedStatus: yup.string(),
  collaborationType: yup.string(),
  defaultFinanceType: yup.string(),
})

const DGIS = RSR.clone().shape({
  iatiActivityId: yup.string().nullable(),
  dateEndPlanned: yup.string().nullable().when('dateEndActual', {
    is: value => value === null || value === '' || value === undefined,
    then: yup.string().nullable().required()
  }),
  defaultAidTypeVocabulary: yup.string(),
  defaultAidType: yup.string().required(),
  defaultFlowType: yup.string().required(),
  defaultTiedStatus: yup.string().required(),
})

const DFID = IATI.clone()

const defs = {
  1: RSR,
  2: IATI,
  3: DGIS,
  5: EUTF,
  6: DFID,
  8: IATI_BASIC
}

export default defs

@@ -840,32 +840,42 @@
   defaultAidType
+Vocabulary
 : yup.string()%0A%7D
@@ -1142,53 +1142,8 @@
 ),%0A 
- defaultAidTypeVocabulary: yup.string(),%0A  //
  def
@@ -1304,24 +1304,74 @@
 p.string(),%0A
+  language: yup.string().default('en').required()%0A
 %7D)%0A%0Aconst DG
@@ -1428,32 +1428,43 @@
 ing().nullable()
+.required()
 ,%0A  dateEndPlann
@@ -1715,32 +1715,79 @@
 g().required(),%0A
+  defaultFinanceType: yup.string().required(),%0A
   defaultFlowTyp
@@ -1860,16 +1860,66 @@
 ired(),%0A
+  language: yup.string().default('en').required()%0A
 %7D)%0A%0Acons

Fix section 1 validations