import{sql as u}from"drizzle-orm";function p(t="r",d="l"){return{id:n("id","id",t,d),organizationId:n("organization_id","organization_id",t,d),projectId:n("project_id","project_id",t,d),key:u.raw(`${t}.key AS key`),type:n("type","type",t,d),title:n("title","title",t,d),summary:n("summary","summary",t,d),tags:_("tags","tags",t,d),metadata:_("metadata","metadata",t,d),git:_("git","git",t,d),contact:_("contact","contact",t,d),links:_("links","links",t,d),createdAt:u.raw(`MIN(${t}.created_at, ${d}.created_at) AS created_at`),updatedAt:u.raw(`MAX(${t}.updated_at, ${d}.updated_at) AS updated_at`),source:n("source","source",t,d),sourceFile:n("source_file","source_file",t,d),fileHash:n("file_hash","file_hash",t,d),version:u.raw(`${t}.version AS version`),revision:u.raw(`${t}.revision AS revision`),hash:n("hash","hash",t,d),isCurrent:n("is_current","is_current",t,d),isDefaultVersion:n("is_default_version","is_default_version",t,d),isDeleted:n("is_deleted","is_deleted",t,d),scorecardsStatus:n("scorecards_status","scorecards_status",t,d)}}function _(t,d,$="r",r="l"){return u.raw(`
    CASE
      WHEN ${$}.${t} IS NULL THEN ${r}.${t}
      WHEN ${r}.${t} IS NULL THEN ${$}.${t}
      WHEN ${$}.updated_at >= ${r}.updated_at THEN json_patch(${r}.${t}, ${$}.${t})
      ELSE json_patch(${$}.${t}, ${r}.${t})
    END AS ${d}
  `)}function n(t,d,$="r",r="l"){return u.raw(`
    CASE
      WHEN ${$}.updated_at >= ${r}.updated_at THEN COALESCE(${$}.${t}, ${r}.${t})
      ELSE COALESCE(${r}.${t}, ${$}.${t})
    END AS ${d}
  `)}export{p as createMergedEntityFieldsForSelect};
