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

-- ActivityRepository.search
select
  "activity".*,
  to_json("user") as "user"
from
  "activity"
  inner join "users" on "users"."id" = "activity"."userId"
  and "users"."deletedAt" is null
  inner join lateral (
    select
      "users"."id",
      "users"."name",
      "users"."email",
      "users"."avatarColor",
      "users"."profileImagePath",
      "users"."profileChangedAt"
    from
      (
        select
          1
      ) as "dummy"
  ) as "user" on true
  left join "assets" on "assets"."id" = "activity"."assetId"
  and "assets"."deletedAt" is null
where
  "activity"."albumId" = $1
order by
  "activity"."createdAt" asc

-- ActivityRepository.create
insert into
  "activity" ("albumId", "userId")
values
  ($1, $2)
returning
  *,
  (
    select
      to_json(obj)
    from
      (
        select
          "id",
          "name",
          "email",
          "avatarColor",
          "profileImagePath",
          "profileChangedAt"
        from
          "users"
        where
          "users"."id" = "activity"."userId"
      ) as obj
  ) as "user"

-- ActivityRepository.delete
delete from "activity"
where
  "id" = $1::uuid

-- ActivityRepository.getStatistics
select
  count(*) as "count"
from
  "activity"
  inner join "users" on "users"."id" = "activity"."userId"
  and "users"."deletedAt" is null
  left join "assets" on "assets"."id" = "activity"."assetId"
where
  "activity"."assetId" = $1
  and "activity"."albumId" = $2
  and "activity"."isLiked" = $3
  and "assets"."deletedAt" is null
