-- NOTE: This file is auto generated by ./sql-generator

-- AccessRepository.activity.checkOwnerAccess
select
  "activity"."id"
from
  "activity"
where
  "activity"."id" in ($1)
  and "activity"."userId" = $2

-- AccessRepository.activity.checkAlbumOwnerAccess
select
  "activity"."id"
from
  "activity"
  left join "album" on "activity"."albumId" = "album"."id"
  and "album"."deletedAt" is null
where
  "activity"."id" in ($1)
  and "album"."ownerId" = $2::uuid

-- AccessRepository.activity.checkCreateAccess
select
  "album"."id"
from
  "album"
  left join "album_user" as "albumUsers" on "albumUsers"."albumsId" = "album"."id"
  left join "user" on "user"."id" = "albumUsers"."usersId"
  and "user"."deletedAt" is null
where
  "album"."id" in ($1)
  and "album"."isActivityEnabled" = $2
  and (
    "album"."ownerId" = $3
    or "user"."id" = $4
  )
  and "album"."deletedAt" is null

-- AccessRepository.album.checkOwnerAccess
select
  "album"."id"
from
  "album"
where
  "album"."id" in ($1)
  and "album"."ownerId" = $2
  and "album"."deletedAt" is null

-- AccessRepository.album.checkSharedAlbumAccess
select
  "album"."id"
from
  "album"
  left join "album_user" on "album_user"."albumsId" = "album"."id"
  left join "user" on "user"."id" = "album_user"."usersId"
  and "user"."deletedAt" is null
where
  "album"."id" in ($1)
  and "album"."deletedAt" is null
  and "user"."id" = $2
  and "album_user"."role" in ($3, $4)

-- AccessRepository.album.checkSharedLinkAccess
select
  "shared_link"."albumId"
from
  "shared_link"
where
  "shared_link"."id" = $1
  and "shared_link"."albumId" in ($2)

-- AccessRepository.asset.checkAlbumAccess
select
  "asset"."id",
  "asset"."livePhotoVideoId"
from
  "album"
  inner join "album_asset" as "albumAssets" on "album"."id" = "albumAssets"."albumsId"
  inner join "asset" on "asset"."id" = "albumAssets"."assetsId"
  and "asset"."deletedAt" is null
  left join "album_user" as "albumUsers" on "albumUsers"."albumsId" = "album"."id"
  left join "user" on "user"."id" = "albumUsers"."usersId"
  and "user"."deletedAt" is null
where
  array["asset"."id", "asset"."livePhotoVideoId"] && array[$1]::uuid[]
  and (
    "album"."ownerId" = $2
    or "user"."id" = $3
  )
  and "album"."deletedAt" is null

-- AccessRepository.asset.checkOwnerAccess
select
  "asset"."id"
from
  "asset"
where
  "asset"."id" in ($1)
  and "asset"."ownerId" = $2
  and "asset"."visibility" != $3

-- AccessRepository.asset.checkPartnerAccess
select
  "asset"."id"
from
  "partner"
  inner join "user" as "sharedBy" on "sharedBy"."id" = "partner"."sharedById"
  and "sharedBy"."deletedAt" is null
  inner join "asset" on "asset"."ownerId" = "sharedBy"."id"
  and "asset"."deletedAt" is null
where
  "partner"."sharedWithId" = $1
  and (
    "asset"."visibility" = 'timeline'
    or "asset"."visibility" = 'hidden'
  )
  and "asset"."id" in ($2)

-- AccessRepository.asset.checkSharedLinkAccess
select
  "asset"."id" as "assetId",
  "asset"."livePhotoVideoId" as "assetLivePhotoVideoId",
  "albumAssets"."id" as "albumAssetId",
  "albumAssets"."livePhotoVideoId" as "albumAssetLivePhotoVideoId"
from
  "shared_link"
  left join "album" on "album"."id" = "shared_link"."albumId"
  and "album"."deletedAt" is null
  left join "shared_link_asset" on "shared_link_asset"."sharedLinksId" = "shared_link"."id"
  left join "asset" on "asset"."id" = "shared_link_asset"."assetsId"
  and "asset"."deletedAt" is null
  left join "album_asset" on "album_asset"."albumsId" = "album"."id"
  left join "asset" as "albumAssets" on "albumAssets"."id" = "album_asset"."assetsId"
  and "albumAssets"."deletedAt" is null
where
  "shared_link"."id" = $1
  and array[
    "asset"."id",
    "asset"."livePhotoVideoId",
    "albumAssets"."id",
    "albumAssets"."livePhotoVideoId"
  ] && array[$2]::uuid[]

-- AccessRepository.authDevice.checkOwnerAccess
select
  "session"."id"
from
  "session"
where
  "session"."userId" = $1
  and "session"."id" in ($2)

-- AccessRepository.memory.checkOwnerAccess
select
  "memory"."id"
from
  "memory"
where
  "memory"."id" in ($1)
  and "memory"."ownerId" = $2
  and "memory"."deletedAt" is null

-- AccessRepository.notification.checkOwnerAccess
select
  "notification"."id"
from
  "notification"
where
  "notification"."id" in ($1)
  and "notification"."userId" = $2

-- AccessRepository.person.checkOwnerAccess
select
  "person"."id"
from
  "person"
where
  "person"."id" in ($1)
  and "person"."ownerId" = $2

-- AccessRepository.person.checkFaceOwnerAccess
select
  "asset_face"."id"
from
  "asset_face"
  left join "asset" on "asset"."id" = "asset_face"."assetId"
  and "asset"."deletedAt" is null
where
  "asset_face"."id" in ($1)
  and "asset"."ownerId" = $2

-- AccessRepository.partner.checkUpdateAccess
select
  "partner"."sharedById"
from
  "partner"
where
  "partner"."sharedById" in ($1)
  and "partner"."sharedWithId" = $2

-- AccessRepository.session.checkOwnerAccess
select
  "session"."id"
from
  "session"
where
  "session"."id" in ($1)
  and "session"."userId" = $2

-- AccessRepository.stack.checkOwnerAccess
select
  "stack"."id"
from
  "stack"
where
  "stack"."id" in ($1)
  and "stack"."ownerId" = $2

-- AccessRepository.tag.checkOwnerAccess
select
  "tag"."id"
from
  "tag"
where
  "tag"."id" in ($1)
  and "tag"."userId" = $2

-- AccessRepository.timeline.checkPartnerAccess
select
  "partner"."sharedById"
from
  "partner"
where
  "partner"."sharedById" in ($1)
  and "partner"."sharedWithId" = $2
