/**
 * Copyright (c) 2023-present Plane Software, Inc. and contributors
 * SPDX-License-Identifier: AGPL-3.0-only
 * See the LICENSE file for details.
 */

import type { TPaginationInfo } from "./common";
import type { TIssue } from "./issues/issue";
import type { IIssueLabel } from "./issues";
import type { IProjectLite } from "./project";
import type { IStateLite } from "./state";
import type { IUser } from "./users";

export type TExternalContourIssue = TIssue & {
  assignee_details?: Pick<IUser, "id" | "display_name" | "avatar_url">[];
  created_by_detail?: Pick<IUser, "id" | "display_name" | "avatar_url"> | null;
  label_details?: { id: string; name: string; color: string }[];
  project_detail?: IProjectLite | null;
  state_detail?: IStateLite | null;
};

export type TExternalContourMirroredAttachment = {
  id: string;
  asset_url?: string | null;
  attributes?: {
    name?: string;
    size?: number;
    type?: string;
  } | null;
  download_url?: string | null;
  updated_at: string;
  uploaded_by?: string | null;
};

export type TExternalContourMirroredComment = {
  id: string;
  comment_html: string;
  created_at: string;
  updated_at: string;
  edited_at?: string | null;
  parent_id?: string | null;
  actor_detail?: Pick<IUser, "id" | "display_name" | "avatar_url"> | null;
};

export type TExternalContourMirroredActivity = {
  id: string;
  verb?: string | null;
  field?: string | null;
  old_value?: string | null;
  new_value?: string | null;
  comment?: string | null;
  created_at: string;
  actor_detail?: Pick<IUser, "id" | "display_name" | "avatar_url"> | null;
};

export type TExternalContourRequest = {
  created_at: string;
  created_by: string | null;
  has_unread_updates?: boolean;
  id: string;
  issue: TExternalContourIssue;
  mirrored_activity?: TExternalContourMirroredActivity[];
  mirrored_attachments?: TExternalContourMirroredAttachment[];
  mirrored_comments?: TExternalContourMirroredComment[];
  source_decision?: "accepted" | null;
  source_decision_at?: string | null;
  source_decision_by_name?: string | null;
  source_project_id: string;
  source_project_name?: string | null;
  target_project_id?: string | null;
  target_project_name?: string | null;
  requested_by_id?: string | null;
  requested_by_name?: string | null;
  requested_at?: string | null;
  status: "open" | "closed";
  updated_at: string;
};

export type TExternalContourRequestResponse = TPaginationInfo & {
  results: TExternalContourRequest[];
};

export type TExternalContourTargetProject = IProjectLite & {
  inbox_view: boolean;
};

export type TExternalContourTargetOptions = {
  project: TExternalContourTargetProject;
  member_ids: string[];
  labels: Pick<IIssueLabel, "id" | "name" | "color" | "parent" | "project_id" | "workspace_id" | "sort_order">[];
};
