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

-- AssetJobRepository.getForSearchDuplicatesJob
select
  "id",
  "type",
  "ownerId",
  "duplicateId",
  "stackId",
  "isVisible",
  "smart_search"."embedding",
  (
    select
      coalesce(json_agg(agg), '[]')
    from
      (
        select
          "asset_files"."id",
          "asset_files"."path",
          "asset_files"."type"
        from
          "asset_files"
        where
          "asset_files"."assetId" = "assets"."id"
          and "asset_files"."type" = $1
      ) as agg
  ) as "files"
from
  "assets"
  left join "smart_search" on "assets"."id" = "smart_search"."assetId"
where
  "assets"."id" = $2::uuid
limit
  $3

-- AssetJobRepository.getForSidecarWriteJob
select
  "id",
  "sidecarPath",
  "originalPath",
  (
    select
      coalesce(json_agg(agg), '[]')
    from
      (
        select
          "tags"."value"
        from
          "tags"
          inner join "tag_asset" on "tags"."id" = "tag_asset"."tagsId"
        where
          "assets"."id" = "tag_asset"."assetsId"
      ) as agg
  ) as "tags"
from
  "assets"
where
  "assets"."id" = $1::uuid
limit
  $2

-- AssetJobRepository.streamForThumbnailJob
select
  "assets"."id",
  "assets"."thumbhash",
  (
    select
      coalesce(json_agg(agg), '[]')
    from
      (
        select
          "asset_files"."id",
          "asset_files"."path",
          "asset_files"."type"
        from
          "asset_files"
        where
          "asset_files"."assetId" = "assets"."id"
      ) as agg
  ) as "files"
from
  "assets"
  inner join "asset_job_status" on "asset_job_status"."assetId" = "assets"."id"
where
  "assets"."deletedAt" is null
  and "assets"."isVisible" = $1
  and (
    "asset_job_status"."previewAt" is null
    or "asset_job_status"."thumbnailAt" is null
    or "assets"."thumbhash" is null
  )

-- AssetJobRepository.getForMigrationJob
select
  "assets"."id",
  "assets"."ownerId",
  "assets"."encodedVideoPath",
  (
    select
      coalesce(json_agg(agg), '[]')
    from
      (
        select
          "asset_files"."id",
          "asset_files"."path",
          "asset_files"."type"
        from
          "asset_files"
        where
          "asset_files"."assetId" = "assets"."id"
      ) as agg
  ) as "files"
from
  "assets"
where
  "assets"."id" = $1

-- AssetJobRepository.getForGenerateThumbnailJob
select
  "assets"."id",
  "assets"."isVisible",
  "assets"."originalFileName",
  "assets"."originalPath",
  "assets"."ownerId",
  "assets"."thumbhash",
  "assets"."type",
  (
    select
      coalesce(json_agg(agg), '[]')
    from
      (
        select
          "asset_files"."id",
          "asset_files"."path",
          "asset_files"."type"
        from
          "asset_files"
        where
          "asset_files"."assetId" = "assets"."id"
      ) as agg
  ) as "files",
  to_json("exif") as "exifInfo"
from
  "assets"
  inner join "exif" on "assets"."id" = "exif"."assetId"
where
  "assets"."id" = $1

-- AssetJobRepository.getForMetadataExtraction
select
  "assets"."id",
  "assets"."checksum",
  "assets"."deviceAssetId",
  "assets"."deviceId",
  "assets"."fileCreatedAt",
  "assets"."fileModifiedAt",
  "assets"."isExternal",
  "assets"."isVisible",
  "assets"."libraryId",
  "assets"."livePhotoVideoId",
  "assets"."localDateTime",
  "assets"."originalFileName",
  "assets"."originalPath",
  "assets"."ownerId",
  "assets"."sidecarPath",
  "assets"."type",
  (
    select
      coalesce(json_agg(agg), '[]')
    from
      (
        select
          "asset_faces".*
        from
          "asset_faces"
        where
          "asset_faces"."assetId" = "assets"."id"
          and "asset_faces"."deletedAt" is null
      ) as agg
  ) as "faces"
from
  "assets"
where
  "assets"."id" = $1

-- AssetJobRepository.getForStorageTemplateJob
select
  "assets"."id",
  "assets"."ownerId",
  "assets"."type",
  "assets"."checksum",
  "assets"."originalPath",
  "assets"."isExternal",
  "assets"."sidecarPath",
  "assets"."originalFileName",
  "assets"."livePhotoVideoId",
  "assets"."fileCreatedAt",
  "exif"."timeZone",
  "exif"."fileSizeInByte"
from
  "assets"
  inner join "exif" on "assets"."id" = "exif"."assetId"
where
  "assets"."deletedAt" is null
  and "assets"."id" = $1

-- AssetJobRepository.streamForStorageTemplateJob
select
  "assets"."id",
  "assets"."ownerId",
  "assets"."type",
  "assets"."checksum",
  "assets"."originalPath",
  "assets"."isExternal",
  "assets"."sidecarPath",
  "assets"."originalFileName",
  "assets"."livePhotoVideoId",
  "assets"."fileCreatedAt",
  "exif"."timeZone",
  "exif"."fileSizeInByte"
from
  "assets"
  inner join "exif" on "assets"."id" = "exif"."assetId"
where
  "assets"."deletedAt" is null

-- AssetJobRepository.streamForDeletedJob
select
  "id",
  "isOffline"
from
  "assets"
where
  "assets"."deletedAt" <= $1
