{"version":3,"file":"required-without-rules.mjs","names":[],"sources":["../../../../../../../../@warlock.js/seal/src/rules/conditional/required-without-rules.ts"],"sourcesContent":["import { get } from \"@mongez/reinforcements\";\r\nimport { getFieldValue, invalidRule, VALID_RULE } from \"../../helpers\";\r\nimport type { SchemaRule } from \"../../types\";\r\nimport { isEmptyValue } from \"./../../helpers/is-empty-value\";\r\n\r\n/**\r\n * Required without rule - field is required if another field is missing\r\n * Supports both global and sibling scope\r\n */\r\nexport const requiredWithoutRule: SchemaRule<{\r\n  field: string;\r\n  scope?: \"global\" | \"sibling\";\r\n}> = {\r\n  name: \"requiredWithout\",\r\n  description: \"The field is required if another field is missing\",\r\n  sortOrder: -2,\r\n  requiresValue: false,\r\n  defaultErrorMessage: \"The :input is required\",\r\n  async validate(value: any, context) {\r\n    const fieldValue = getFieldValue(this, context);\r\n\r\n    // Field is required if the other field is missing\r\n    if (isEmptyValue(value) && fieldValue === undefined) {\r\n      this.context.translatableParams.field = this.context.options.field;\r\n      return invalidRule(this, context);\r\n    }\r\n\r\n    return VALID_RULE;\r\n  },\r\n};\r\n\r\n/**\r\n * Required without all rule - field is required if all specified fields are missing\r\n * Supports both global and sibling scope\r\n */\r\nexport const requiredWithoutAllRule: SchemaRule<{\r\n  fields: string[];\r\n  scope?: \"global\" | \"sibling\";\r\n}> = {\r\n  name: \"requiredWithoutAll\",\r\n  description: \"The field is required if all specified fields are missing\",\r\n  sortOrder: -2,\r\n  requiresValue: false,\r\n  defaultErrorMessage: \"The :input is required\",\r\n  async validate(value: any, context) {\r\n    const { fields, scope = \"global\" } = this.context.options;\r\n    const source = scope === \"sibling\" ? context.parent : context.allValues;\r\n\r\n    // Check if all fields are missing\r\n    const allMissing = fields.every((field) => get(source, field) === undefined);\r\n\r\n    // Field is required if all other fields are missing\r\n    if (isEmptyValue(value) && allMissing) {\r\n      return invalidRule(this, context);\r\n    }\r\n\r\n    return VALID_RULE;\r\n  },\r\n};\r\n\r\n/**\r\n * Required without any rule - field is required if any of the specified fields is missing\r\n * Supports both global and sibling scope\r\n */\r\nexport const requiredWithoutAnyRule: SchemaRule<{\r\n  fields: string[];\r\n  scope?: \"global\" | \"sibling\";\r\n}> = {\r\n  name: \"requiredWithoutAny\",\r\n  description: \"The field is required if any of the specified fields is missing\",\r\n  sortOrder: -2,\r\n  requiresValue: false,\r\n  defaultErrorMessage: \"The :input is required\",\r\n  async validate(value: any, context) {\r\n    const { fields, scope = \"global\" } = this.context.options;\r\n    const source = scope === \"sibling\" ? context.parent : context.allValues;\r\n\r\n    // Check if any field is missing\r\n    const anyMissing = fields.some((field) => get(source, field) === undefined);\r\n\r\n    // Field is required if any other field is missing\r\n    if (isEmptyValue(value) && anyMissing) {\r\n      return invalidRule(this, context);\r\n    }\r\n\r\n    return VALID_RULE;\r\n  },\r\n};\r\n"],"mappings":";;;;;;;;;;;AASA,MAAa,sBAGR;CACH,MAAM;CACN,aAAa;CACb,WAAW;CACX,eAAe;CACf,qBAAqB;CACrB,MAAM,SAAS,OAAY,SAAS;EAClC,MAAM,aAAa,cAAc,MAAM,OAAO;EAG9C,IAAI,aAAa,KAAK,KAAK,eAAe,QAAW;GACnD,KAAK,QAAQ,mBAAmB,QAAQ,KAAK,QAAQ,QAAQ;GAC7D,OAAO,YAAY,MAAM,OAAO;EAClC;EAEA,OAAO;CACT;AACF;;;;;AAMA,MAAa,yBAGR;CACH,MAAM;CACN,aAAa;CACb,WAAW;CACX,eAAe;CACf,qBAAqB;CACrB,MAAM,SAAS,OAAY,SAAS;EAClC,MAAM,EAAE,QAAQ,QAAQ,aAAa,KAAK,QAAQ;EAClD,MAAM,SAAS,UAAU,YAAY,QAAQ,SAAS,QAAQ;EAG9D,MAAM,aAAa,OAAO,OAAO,UAAU,IAAI,QAAQ,KAAK,MAAM,MAAS;EAG3E,IAAI,aAAa,KAAK,KAAK,YACzB,OAAO,YAAY,MAAM,OAAO;EAGlC,OAAO;CACT;AACF;;;;;AAMA,MAAa,yBAGR;CACH,MAAM;CACN,aAAa;CACb,WAAW;CACX,eAAe;CACf,qBAAqB;CACrB,MAAM,SAAS,OAAY,SAAS;EAClC,MAAM,EAAE,QAAQ,QAAQ,aAAa,KAAK,QAAQ;EAClD,MAAM,SAAS,UAAU,YAAY,QAAQ,SAAS,QAAQ;EAG9D,MAAM,aAAa,OAAO,MAAM,UAAU,IAAI,QAAQ,KAAK,MAAM,MAAS;EAG1E,IAAI,aAAa,KAAK,KAAK,YACzB,OAAO,YAAY,MAAM,OAAO;EAGlC,OAAO;CACT;AACF"}