import{getOrganizationById as e}from"../../services/organization.service.mjs";import{z as t}from"zod";const n=[`name`,`membersIds`,`adminsIds`,`organizationId`],r=4,i=100,a=1,o=t.object({name:t.string({message:`Name must be a string.`}).min(4,`Name must be at least 4 characters long.`).max(100,`Name must be at most 100 characters long.`),organizationId:t.string({message:`Organization id must be a string`}),membersIds:t.array(t.string({message:`Members must contain only string elements.`})).min(1,`Members must be at least 1 items long.`),adminsIds:t.array(t.string({message:`Members must contain only string elements.`})).min(1,`Members must be at least 1 items long.`)}),s=async(t,r=n)=>{let i=r.reduce((e,t)=>(e[t]=!0,e),{}),a=o.pick(i).safeParse(t),s=a.success?{}:a.error.flatten().fieldErrors;if(r.includes(`organizationId`)||r.includes(`membersIds`)||r.includes(`adminsIds`))try{if(r.includes(`organizationId`)&&t.organizationId&&!s.organizationId&&(await e(t.organizationId.toString())||(s.organizationId=[`Organization not found`])),t.organizationId){let n=await e(t.organizationId.toString());if(n){let e=n.membersIds.map(String);r.includes(`membersIds`)&&t.membersIds&&t.membersIds.filter(t=>!e.includes(String(t))).length>0&&(s.membersIds=s.membersIds||[],s.membersIds.push(`Members must contain valid elements.`)),r.includes(`adminsIds`)&&t.adminsIds&&t.adminsIds.filter(t=>!e.includes(String(t))).length>0&&(s.adminsIds=s.adminsIds||[],s.adminsIds.push(`Members must contain valid elements.`))}}else (r.includes(`membersIds`)||r.includes(`adminsIds`))&&(r.includes(`membersIds`)&&(s.membersIds=s.membersIds||[],s.membersIds.push(`Organization id is required to validate project members`)),r.includes(`adminsIds`)&&(s.adminsIds=s.adminsIds||[],s.adminsIds.push(`Organization id is required to validate project members`)))}catch{r.includes(`organizationId`)&&t.organizationId&&(s.organizationId=[`Organization not found`])}for(let e of Object.keys(s))s[e]?.length===0&&delete s[e];return s};export{a as MEMBERS_MIN_LENGTH,i as NAME_MAX_LENGTH,r as NAME_MIN_LENGTH,s as validateProject};
//# sourceMappingURL=validateProject.mjs.map