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

-- StackRepository.search
select
  "asset_stack".*,
  (
    select
      coalesce(json_agg(agg), '[]')
    from
      (
        select
          "assets".*,
          to_json("exifInfo") as "exifInfo"
        from
          "assets"
          inner join lateral (
            select
              "exif"."assetId",
              "exif"."autoStackId",
              "exif"."bitsPerSample",
              "exif"."city",
              "exif"."colorspace",
              "exif"."country",
              "exif"."dateTimeOriginal",
              "exif"."description",
              "exif"."exifImageHeight",
              "exif"."exifImageWidth",
              "exif"."exposureTime",
              "exif"."fileSizeInByte",
              "exif"."fNumber",
              "exif"."focalLength",
              "exif"."fps",
              "exif"."iso",
              "exif"."latitude",
              "exif"."lensModel",
              "exif"."livePhotoCID",
              "exif"."longitude",
              "exif"."make",
              "exif"."model",
              "exif"."modifyDate",
              "exif"."orientation",
              "exif"."profileDescription",
              "exif"."projectionType",
              "exif"."rating",
              "exif"."state",
              "exif"."timeZone"
            from
              "exif"
            where
              "exif"."assetId" = "assets"."id"
          ) as "exifInfo" on true
        where
          "assets"."deletedAt" is null
          and "assets"."stackId" = "asset_stack"."id"
          and "assets"."visibility" in ('archive', 'timeline')
      ) as agg
  ) as "assets"
from
  "asset_stack"
where
  "asset_stack"."ownerId" = $1

-- StackRepository.delete
delete from "asset_stack"
where
  "id" = $1::uuid

-- StackRepository.getById
select
  *,
  (
    select
      coalesce(json_agg(agg), '[]')
    from
      (
        select
          "assets".*,
          (
            select
              coalesce(json_agg(agg), '[]')
            from
              (
                select
                  "tags"."id",
                  "tags"."value",
                  "tags"."createdAt",
                  "tags"."updatedAt",
                  "tags"."color",
                  "tags"."parentId"
                from
                  "tags"
                  inner join "tag_asset" on "tags"."id" = "tag_asset"."tagsId"
                where
                  "tag_asset"."assetsId" = "assets"."id"
              ) as agg
          ) as "tags",
          to_json("exifInfo") as "exifInfo"
        from
          "assets"
          inner join lateral (
            select
              "exif"."assetId",
              "exif"."autoStackId",
              "exif"."bitsPerSample",
              "exif"."city",
              "exif"."colorspace",
              "exif"."country",
              "exif"."dateTimeOriginal",
              "exif"."description",
              "exif"."exifImageHeight",
              "exif"."exifImageWidth",
              "exif"."exposureTime",
              "exif"."fileSizeInByte",
              "exif"."fNumber",
              "exif"."focalLength",
              "exif"."fps",
              "exif"."iso",
              "exif"."latitude",
              "exif"."lensModel",
              "exif"."livePhotoCID",
              "exif"."longitude",
              "exif"."make",
              "exif"."model",
              "exif"."modifyDate",
              "exif"."orientation",
              "exif"."profileDescription",
              "exif"."projectionType",
              "exif"."rating",
              "exif"."state",
              "exif"."timeZone"
            from
              "exif"
            where
              "exif"."assetId" = "assets"."id"
          ) as "exifInfo" on true
        where
          "assets"."deletedAt" is null
          and "assets"."stackId" = "asset_stack"."id"
          and "assets"."visibility" in ('archive', 'timeline')
      ) as agg
  ) as "assets"
from
  "asset_stack"
where
  "id" = $1::uuid
