import { ValidationArraySchema } from '~/domain'; import { IAnySchema } from '~/domain/entities/schemas/any-schema'; import { JoiSchema } from '~/infra/joi/helper/joi-types'; import { ArrayParser } from '~/infra/joi/protocols'; import { JoiCommonRulesParser } from '~/infra/joi/validators/use-cases/joi-common-validator/joi-common-rule-parser'; export class JoiArrayRulesParser extends JoiCommonRulesParser<'array'> implements ArrayParser { items = (schema: ArrayParser.Schema, item: ValidationArraySchema.Item): ArrayParser.Schema => { return schema.items(this.parseSchema.parseSchema(item)); }; has = (schema: ArrayParser.Schema, value: IAnySchema): ArrayParser.Schema => { return schema.has(this.parseSchema.parseSchema(value)); }; length = (schema: ArrayParser.Schema, value: number): ArrayParser.Schema => { return schema.length(value); }; max = (schema: ArrayParser.Schema, value: number): ArrayParser.Schema => { return schema.max(value); }; required = (schema: JoiSchema<'array'>, value: boolean) => { if (value) { return schema.required(); } else { return schema; } }; }